#include <iostream>
#include <cstdio>

using namespace std;

#define For(i , a , b) for (int i = a , _b = b ; i <= _b ; ++i)
#define Ford(i , a  ,b) for (int i = a , _b = b : i >= _b ; --i)
#define Rep(i , n) for (int i = 0 , _n = n ; i < _n ; ++i)
#define sz(A) ((int)A.size())
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)

typedef pair<int , int> pt;

const int md = 1000000 + 3;

long long n , k;

int mul(int a , int b) {
	return 1LL * a * b % md;
}

int pwr(long long a , long long n) {
	a %= md;
	int res = 1;
	while (n) {
		if (n & 1) res = mul(res , a); n >>= 1; a = mul(a , a);
	}
	return res;
}

int Minus(int a , int b) {
	return ((a - b) % md + md) % md;
}

void ReadData() {
	cin >> n >> k;
}

long long cal(int val , long long k) {
	if (val == 0) return k / md;
	if (k % md >= val) return (k / md) + 1;
	return k / md;
}

int mauso() {
	int z = pwr(2 , n); return pwr(z , k - 1);
}

void fail() {
	int x = 0;
	For(i , 0 , 62) {
		if ((1LL << i) >= k - 1) {
			if (i >= n) {
				cout << "1 1" << endl;
				exit(0);
			}
			return;
		}
	}
}

int tuso() {
	int z = pwr(2 , n);
	int res = 1;
	For(i , 0 , md - 1) {
		int need = Minus(z , i);
		res = mul(res , pwr(i , cal(need , k - 1)));
	}
	return Minus(mauso() , res);
}

long long z2(long long k) {
	long long cur = 2;
	long long res = 0;
	while (cur <= k) {
		res += k / cur; cur *= 2;
	}
	return res ;
}

void Process() {
	fail();
	int gcd = pwr(2 , z2( k - 1) );
	int rev = pwr(gcd , md - 2);
	int tu = mul(tuso() , rev);
	int mau = mul(mauso() , rev);

	cout << tu << " " << mau << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	//freopen("input.inp" , "r" , stdin);
	ReadData();
	Process();

	return 0;

}


#include <iostream>
#include <cstdio>

using namespace std;

#define For(i , a , b) for (int i = a , _b = b ; i <= _b ; ++i)
#define Ford(i , a  ,b) for (int i = a , _b = b : i >= _b ; --i)
#define Rep(i , n) for (int i = 0 , _n = n ; i < _n ; ++i)
#define sz(A) ((int)A.size())
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)

typedef pair<int , int> pt;

const int md = 1000000 + 3;

long long n , k;

int mul(int a , int b) {
	return 1LL * a * b % md;
}

int pwr(long long a , long long n) {
	a %= md;
	int res = 1;
	while (n) {
		if (n & 1) res = mul(res , a); n >>= 1; a = mul(a , a);
	}
	return res;
}

int Minus(int a , int b) {
	return ((a - b) % md + md) % md;
}

void ReadData() {
	cin >> n >> k;
}

long long cal(int val , long long k) {
	if (val == 0) return k / md;
	if (k % md >= val) return (k / md) + 1;
	return k / md;
}

int mauso() {
	int z = pwr(2 , n); return pwr(z , k - 1);
}

void fail() {
	int x = 0;
	For(i , 0 , 62) {
		if ((1LL << i) >= k) {
			if (i >= n) {
				cout << "1 1" << endl;
				exit(0);
			}
			return;
		}
	}
}

int tuso() {
	int z = pwr(2 , n);
	int res = 1;
	For(i , 0 , md - 1) {
		int need = Minus(z , i);
		res = mul(res , pwr(i , cal(need , k - 1)));
	}
	return Minus(mauso() , res);
}

long long z2(long long k) {
	long long cur = 2;
	long long res = 0;
	while (cur <= k) {
		res += k / cur; cur *= 2;
	}
	return res ;
}

void Process() {
	fail();
	int gcd = pwr(2 , z2( k - 1) );
	int rev = pwr(gcd , md - 2);
	int tu = mul(tuso() , rev);
	int mau = mul(mauso() , rev);

	cout << tu << " " << mau << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	//freopen("input.inp" , "r" , stdin);
	ReadData();
	Process();

	return 0;

}


#include <iostream>
#include <cstdio>

using namespace std;

#define For(i , a , b) for (int i = a , _b = b ; i <= _b ; ++i)
#define Ford(i , a  ,b) for (int i = a , _b = b : i >= _b ; --i)
#define Rep(i , n) for (int i = 0 , _n = n ; i < _n ; ++i)
#define sz(A) ((int)A.size())
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)

typedef pair<int , int> pt;

const int md = 1000000 + 3;

long long n , k;

int mul(int a , int b) {
	return 1LL * a * b % md;
}

int pwr(long long a , long long n) {
	a %= md;
	int res = 1;
	while (n) {
		if (n & 1) res = mul(res , a); n >>= 1; a = mul(a , a);
	}
	return res;
}

int Minus(int a , int b) {
	return ((a - b) % md + md) % md;
}

void ReadData() {
	cin >> n >> k;
}

long long cal(int val , long long k) {
	if (val == 0) return k / md;
	if (k % md >= val) return (k / md) + 1;
	return k / md;
}

int mauso() {
	int z = pwr(2 , n); return pwr(z , k - 1);
}

void fail() {
	int x = 0;
	if (n >= 63) return;
	if ((1LL << n) <= k - 1) {
		cout << "1 1" << endl; exit(0);
	}

}

int tuso() {
	int z = pwr(2 , n);
	int res = 1;
	For(i , 0 , md - 1) {
		int need = Minus(z , i);
		res = mul(res , pwr(i , cal(need , k - 1)));
	}
	return Minus(mauso() , res);
}

long long z2(long long k) {
	long long cur = 2;
	long long res = 0;
	while (cur <= k) {
		res += k / cur; cur *= 2;
	}
	return res ;
}

void Process() {
	fail();
	int gcd = pwr(2 , z2( k - 1) );
	int rev = pwr(gcd , md - 2);
	int tu = mul(tuso() , rev);
	int mau = mul(mauso() , rev);

	cout << tu << " " << mau << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	//freopen("input.inp" , "r" , stdin);
	ReadData();
	Process();

	return 0;

}


#include <iostream>
#include <cstdio>

using namespace std;

#define For(i , a , b) for (int i = a , _b = b ; i <= _b ; ++i)
#define Ford(i , a  ,b) for (int i = a , _b = b : i >= _b ; --i)
#define Rep(i , n) for (int i = 0 , _n = n ; i < _n ; ++i)
#define sz(A) ((int)A.size())
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)

typedef pair<int , int> pt;

const int md = 1000000 + 3;

long long n , k;

int mul(int a , int b) {
	return 1LL * a * b % md;
}

int pwr(long long a , long long n) {
	a %= md;
	int res = 1;
	while (n) {
		if (n & 1) res = mul(res , a); n >>= 1; a = mul(a , a);
	}
	return res;
}

int Minus(int a , int b) {
	return ((a - b) % md + md) % md;
}

void ReadData() {
	cin >> n >> k;
}

long long cal(int val , long long k) {
	if (val == 0) return k / md;
	if (k % md >= val) return (k / md) + 1;
	return k / md;
}

int mauso() {
	int z = pwr(2 , n); return pwr(z , k - 1);
}

void fail() {
	int x = 0;
	For(i , 0 , 62) {
		if ((1LL << i) >= k - 1) {
			if (i - 1 >= n) {
				cout << "1 1" << endl;
				exit(0);
			}
			return;
		}
	}
}

int tuso() {
	int z = pwr(2 , n);
	int res = 1;
	For(i , 0 , md - 1) {
		int need = Minus(z , i);
		res = mul(res , pwr(i , cal(need , k - 1)));
	}
	return Minus(mauso() , res);
}

long long z2(long long k) {
	long long cur = 2;
	long long res = 0;
	while (cur <= k) {
		res += k / cur; cur *= 2;
	}
	return res ;
}

void Process() {
	fail();
	int gcd = pwr(2 , z2( k - 1) );
	int rev = pwr(gcd , md - 2);
	int tu = mul(tuso() , rev);
	int mau = mul(mauso() , rev);

	cout << tu << " " << mau << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	//freopen("input.inp" , "r" , stdin);
	ReadData();
	Process();

	return 0;

}


#include <iostream>
#include <cmath>
#include <unordered_map>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a){
    ll res = 0;
    ll div = 2;
    while(div <= a){
        res += a / div;
        if(a - div < div){
            break;
        }
        div *= 2;
    }
    return res;
}

const ll mod = 1000003ULL;

unordered_map<ll, ll> dp;

ll mod2exp(ll p){
    if(dp.find(p) != dp.end()){
        return dp[p];
    }
    return dp[p] = (mod2exp(p/2) * mod2exp(p/2 + p % 2)) % mod;
}

int main(){
    ll n, k;
    cin>>n>>k;
    if(log2(k) > n){
        cout<<1<<" "<<1;
        return 0;
    }
    dp[0] = 1;
    dp[1] = 2;
    ll g = gcd(k-1);
    ll b = mod2exp(((n % (mod-1)) * ((k-1) % (mod-1)) - (g % (mod-1)) + (mod-1)) % (mod-1));
    ll a = 1;
    if(k-1 >= mod){
        a = 0;
    } else {
        int erased = 0;
        for(ll i = k-1; i >= 1;--i){
            int twos = 0;
            for(int p = i;p % 2 == 0;p /= 2, twos++)
                ;
            int rm = 0;
            if(erased < g && twos > 0){
                rm = min(twos, (int)g - erased);
                erased += rm;
            }
            a *= (mod2exp(n-rm) - (i / mod2exp(rm)) + mod) % mod;
            a %= mod;
        }
    }
    a = (b - a + mod) % mod;
    cout<<a<<" "<<b;
    return 0;
}


#include <iostream>
#include <cmath>
#include <unordered_map>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a){
    ll res = 0;
    ll div = 2;
    while(div <= a){
        res += a / div;
        if(a - div < div){
            break;
        }
        div *= 2;
    }
    return res;
}

const ll mod = 1000003ULL;

unordered_map<ll, ll> dp;

ll mod2exp(ll p){
    if(dp.find(p) != dp.end()){
        return dp[p];
    }
    return dp[p] = (mod2exp(p/2) * mod2exp(p/2 + p % 2)) % mod;
}

bool bigger(ll k, ll n){
    ll curr = 1;
    while(n > 0){
        if(k - curr < curr){
            return false;
        }
        curr *= 2;
        n--;
    }
    return k > curr;
}

int main(){
    ll n, k;
    cin>>n>>k;
    if(bigger(k,n)){
        cout<<1<<" "<<1;
        return 0;
    }
    dp[0] = 1;
    dp[1] = 2;
    ll g = gcd(k-1);
    ll b = mod2exp(((n % (mod-1)) * ((k-1) % (mod-1)) - (g % (mod-1)) + (mod-1)) % (mod-1));
    ll a = 1;
    if(k-1 >= mod){
        a = 0;
    } else {
        int erased = 0;
        for(ll i = k-1; i >= 1;--i){
            int twos = 0;
            for(int p = i;p % 2 == 0;p /= 2, twos++)
                ;
            int rm = 0;
            if(erased < g && twos > 0){
                rm = min(twos, (int)g - erased);
                erased += rm;
            }
            a *= (mod2exp(n-rm) - (i / mod2exp(rm)) + mod) % mod;
            a %= mod;
        }
    }
    a = (b - a + mod) % mod;
    cout<<a<<" "<<b;
    return 0;
}


#include <iostream>
#include <cmath>
#include <unordered_map>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a){
    ll res = 0;
    ll div = 2;
    while(div <= a){
        res += a / div;
        if(a - div < div){
            break;
        }
        div *= 2;
    }
    return res;
}

const ll mod = 1000003ULL;

unordered_map<ll, ll> dp;

ll mod2exp(ll p){
    if(dp.find(p) != dp.end()){
        return dp[p];
    }
    return dp[p] = (mod2exp(p/2) * mod2exp(p/2 + p % 2)) % mod;
}

int main(){
    ll n, k;
    cin>>n>>k;
    if(log2(k) > n){
        cout<<1<<" "<<1;
        return 0;
    }
    dp[0] = 1;
    dp[1] = 2;
    ll g = gcd(k-1);
    ll b = mod2exp(((n) * ((k-1) % (mod-1)) - g + (mod-1)) % (mod-1));
    ll a = 1;
    if(k-1 >= mod){
        a = 0;
    } else {
        int erased = 0;
        for(ll i = k-1; i >= 1;--i){
            int twos = 0;
            for(int p = i;p % 2 == 0;p /= 2, twos++)
                ;
            int rm = 0;
            if(erased < g && twos > 0){
                rm = min(twos, (int)g - erased);
                erased += rm;
            }
            a *= (mod2exp(n-rm) - (i / mod2exp(rm)) + mod) % mod;
            a %= mod;
        }
    }
    a = (b - a + mod) % mod;
    cout<<a<<" "<<b;
    return 0;
}


#include <iostream>
#include <cmath>
#include <unordered_map>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a){
    ll res = 0;
    ll div = 2;
    while(div <= a){
        res += a / div;
        if(a - div < div){
            break;
        }
        div *= 2;
    }
    return res;
}

const ll mod = 1000003ULL;

unordered_map<ll, ll> dp;

ll mod2exp(ll p){
    if(dp.find(p) != dp.end()){
        return dp[p];
    }
    return dp[p] = (mod2exp(p/2) * mod2exp(p/2 + p % 2)) % mod;
}

int main(){
    ll n, k;
    cin>>n>>k;
    if(ceil(log2(k)) > n){
        cout<<1<<" "<<1;
        return 0;
    }
    dp[0] = 1;
    dp[1] = 2;
    ll g = gcd(k-1);
    ll b = mod2exp(((n % (mod-1)) * ((k-1) % (mod-1)) - (g % (mod-1)) + (mod-1)) % (mod-1));
    ll a = 1;
    if(k-1 >= mod){
        a = 0;
    } else {
        int erased = 0;
        for(ll i = k-1; i >= 1;--i){
            int twos = 0;
            for(int p = i;p % 2 == 0;p /= 2, twos++)
                ;
            int rm = 0;
            if(erased < g && twos > 0){
                rm = min(twos, (int)g - erased);
                erased += rm;
            }
            a *= (mod2exp(n-rm) - (i / mod2exp(rm)) + mod) % mod;
            a %= mod;
        }
    }
    a = (b - a + mod) % mod;
    cout<<a<<" "<<b;
    return 0;
}


#include <iostream>
#include <cmath>
#include <unordered_map>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a){
    ll res = 0;
    ll div = 2;
    while(div <= a){
        res += a / div;
        if(a - div < div){
            break;
        }
        div *= 2;
    }
    return res;
}

const ll mod = 1000003ULL;

unordered_map<ll, ll> dp;

ll mod2exp(ll p){
    if(dp.find(p) != dp.end()){
        return dp[p];
    }
    return dp[p] = (mod2exp(p/2) * mod2exp(p/2 + p % 2)) % mod;
}

int main(){
    ll n, k;
    cin>>n>>k;
    if(ceil(log2(k)) >= n){
        cout<<1<<" "<<1;
        return 0;
    }
    dp[0] = 1;
    dp[1] = 2;
    ll g = gcd(k-1);
    ll b = mod2exp(((n % (mod-1)) * ((k-1) % (mod-1)) - (g % (mod-1)) + (mod-1)) % (mod-1));
    ll a = 1;
    if(k-1 >= mod){
        a = 0;
    } else {
        int erased = 0;
        for(ll i = k-1; i >= 1;--i){
            int twos = 0;
            for(int p = i;p % 2 == 0;p /= 2, twos++)
                ;
            int rm = 0;
            if(erased < g && twos > 0){
                rm = min(twos, (int)g - erased);
                erased += rm;
            }
            a *= (mod2exp(n-rm) - (i / mod2exp(rm)) + mod) % mod;
            a %= mod;
        }
    }
    a = (b - a + mod) % mod;
    cout<<a<<" "<<b;
    return 0;
}


#include <iostream>
#include <cmath>
#include <unordered_map>
using namespace std;
typedef unsigned long long ll;

ll gcd(ll a){
    ll res = 0;
    ll div = 2;
    while(div <= a){
        res += a / div;
        if(a - div < div){
            break;
        }
        div *= 2;
    }
    return res;
}

const ll mod = 1000003ULL;

unordered_map<ll, ll> dp;

ll mod2exp(ll p){
    if(dp.find(p) != dp.end()){
        return dp[p];
    }
    return dp[p] = (mod2exp(p/2) * mod2exp(p/2 + p % 2)) % mod;
}

bool bigger(ll k, ll n){
    ll curr = 1;
    while(n > 0){
        if(k - curr < curr){
            return true;
        }
        curr *= 2;
        n--;
    }
    return k > curr;
}

int main(){
    ll n, k;
    cin>>n>>k;
    if(bigger(k,n)){
        cout<<1<<" "<<1;
        return 0;
    }
    dp[0] = 1;
    dp[1] = 2;
    ll g = gcd(k-1);
    ll b = mod2exp(((n % (mod-1)) * ((k-1) % (mod-1)) - (g % (mod-1)) + (mod-1)) % (mod-1));
    ll a = 1;
    if(k-1 >= mod){
        a = 0;
    } else {
        int erased = 0;
        for(ll i = k-1; i >= 1;--i){
            int twos = 0;
            for(int p = i;p % 2 == 0;p /= 2, twos++)
                ;
            int rm = 0;
            if(erased < g && twos > 0){
                rm = min(twos, (int)g - erased);
                erased += rm;
            }
            a *= (mod2exp(n-rm) - (i / mod2exp(rm)) + mod) % mod;
            a %= mod;
        }
    }
    a = (b - a + mod) % mod;
    cout<<a<<" "<<b;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e6+3;
ll twos(ll x){
    if(x%2)
        return 0;
    return twos(x/2)+1;
}
ll mask = (1LL<<30)-1;
ll get2(ll n, ll i){
//    cout << n << ' ' << i << '\n';
    if(n <= 30)
        return  twos((1<<n)-i);
    --i;
    ll tmp = mask-i;
    return twos(tmp);

}
ll ipow(ll a, ll p){
    if(p==0)
        return 1;
    if(p==1)
        return a;
    return ipow((a*a)%MOD,p/2)*ipow(a,p%2)%MOD;
}
ll f(ll n, ll i){
    ll tmp = twos(i);
    return (ipow(2,n-tmp)-(i>>tmp));
}
int main(){
    ll n,k;
    cin >> n >> k;
    // 2^(k*n-n) - (2^n-1)!/(2^n-k)!
    // 2^(k*n-n)
    if(n <= 61 && (1LL<<n) < k){
        puts("1 1");
        return 0;
    }
    if(k > MOD){
        puts("1 1");
        return 0;
    }
    ll a=1,b=1,c=1,d=0;
    for(int i = 1; i < k; ++i){
        d += get2(n,i);
    }
    // 2^(k*n-n-d) - (2^n-1)*...*(2^n-k+1)/2^d
    // 2^(k*n-n-d)
    for(int i = 1; i < k; ++i)
        b = (b*f(n,i))%MOD;
//    cout << d << '\n';
    k%=(MOD-1);
    n%=(MOD-1);
    ll in = (k*n-n-d)%(MOD-1)+(MOD-1);
    a = ((ipow(2,in)-b)%MOD+MOD)%MOD;
    b = ipow(2,in);
    cout << a << ' ' << b << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e6+3;
ll ipow(ll a, ll p){
    if(p == 0)
        return 1;
    if(p == 1)
        return a;
    return ipow(a*a%MOD,p/2)*ipow(a,p%2)%MOD;
}
ll f(ll n, ll k){
    if(k > MOD)
        return 0;
    ll ans = 1;
    for(int i = 1; i <= k; ++i){
        int p2 = __builtin_ctz(i);
        ans = (ans * (ipow(2,n-p2)-(i>>p2)))%MOD;
    }
    return (ans+MOD)%MOD;
}
int main(){
    // 1 - (n-1)*(n-2)*...*(n-k+1) / (n)^(k-1)
    ll n,k;
    cin >> n >> k;
    if(n < 60 && (1LL<<n) < k){
        puts("1 1");
        return 0;
    }
    --k;
    // (2^n*k)) - (2^n-1)*(2^n-2)*...*(2^n-k)
    // (2^n*k))
    ll d = 0;
    for(int i = 1; i < 60; ++i)
        d += k/(1LL<<i);
    ll c = f(n,k);
    n %= (MOD-1);
    k %= (MOD-1);
    ll p = ((n*k-d)%(MOD-1)+MOD-1)%(MOD-1);
    ll a = (ipow(2,p)-c+MOD)%MOD;
    ll b = ipow(2,p);
    cout << a << ' ' << b << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e6+3;
ll ipow(ll a, ll p){
    if(p == 0)
        return 1;
    if(p == 1)
        return a;
    return ipow(a*a%MOD,p/2)*ipow(a,p%2)%MOD;
}
ll f(ll n, ll k){
    if(k > MOD)
        return 0;
    ll ans = 1;
    for(int i = 1; i <= k; ++i){
        int p2 = __builtin_ctz(i);
        ans = (ans * (ipow(2,n-p2)-i/(1<<p2)))%MOD;
    }
    return (ans+MOD)%MOD;
}
int main(){
    // 1 - (n-1)*(n-2)*...*(n-k+1) / (n)^(k-1)
    ll n,k;
    cin >> n >> k;
    if(n < 60 && (1LL<<n) < k){
        puts("1 1");
        return 0;
    }
    --k;
    // (2^n*k)) - (2^n-1)*(2^n-2)*...*(2^n-k)
    // (2^n*k))
    ll d = 0;
    for(int i = 1; i < 60; ++i)
        d += k/(1LL<<i);
    ll c = f(n,k);
    n %= (MOD-1);
    k %= (MOD-1);
    ll p = (n*k-d+MOD-1)%(MOD-1);
    ll a = (ipow(2,p)-c+MOD)%MOD;
    ll b = ipow(2,p);
    cout << a << ' ' << b << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e6+3;
ll ipow(ll a, ll p){
    if(p == 0)
        return 1;
    if(p == 1)
        return a;
    return ipow(a*a%MOD,p/2)*ipow(a,p%2)%MOD;
}
ll f(ll n, ll k){
    if(k > MOD)
        return 0;
    ll ans = 1;
    ll m = ipow(2,n);
    for(int i = 1; i <= k; ++i){
        if(--m < 0)
            m += MOD;
        ans = ans*m%MOD;
    }
    return ans;
}
int main(){
    // 1 - (n-1)*(n-2)*...*(n-k+1) / (n)^(k-1)
    ll n,k;
    cin >> n >> k;
    if(n < 60 && (1LL<<n) < k){
        puts("1 1");
        return 0;
    }
    --k;
    // (2^n*k)) - (2^n-1)*(2^n-2)*...*(2^n-k)
    // (2^n*k))
    ll d = 0;
    for(int i = 1; i < 60; ++i)
        d += k/(1LL<<i);
    ll c = f(n,k);
    c = (c*ipow((ipow(2,d)),MOD-2))%MOD;
    n %= (MOD-1);
    k %= (MOD-1);
    ll p = ((n*k-d)%(MOD-1)+MOD-1)%(MOD-1);
    ll a = (ipow(2,p)-c+MOD)%MOD;
    ll b = ipow(2,p);
    cout << a << ' ' << b << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e6+3;
ll twos(ll x){
    if(x%2)
        return 0;
    return twos(x/2)+1;
}
ll mask = (1LL<<30)-1;
ll get2(ll n, ll i){
//    cout << n << ' ' << i << '\n';
    if(n <= 30)
        return  twos((1<<n)-i);
    --i;
    ll tmp = mask-i;
    return twos(tmp);

}
ll ipow(ll a, ll p){
    if(p==0)
        return 1;
    if(p==1)
        return a;
    return ipow((a*a)%MOD,p/2)*ipow(a,p%2)%MOD;
}
ll f(ll n, ll i){
    ll tmp = twos(i);
    return (ipow(2,n-tmp)-(i>>tmp));
}
int main(){
    ll n,k;
    cin >> n >> k;
    // 2^(k*n-n) - (2^n-1)!/(2^n-k)!
    // 2^(k*n-n)
    if(n <= 61 && (1LL<<n) < k){
        puts("1 1");
        return 0;
    }
    if(k > 2*MOD){
        puts("1 1");
        return 0;
    }
    ll a=1,b=1,c=1,d=0;
    for(int i = 1; i < k; ++i){
        d += get2(n,i);
    }
    // 2^(k*n-n-d) - (2^n-1)*...*(2^n-k+1)/2^d
    // 2^(k*n-n-d)
    for(int i = 1; i < k; ++i)
        b = (b*f(n,i))%MOD;
//    cout << d << '\n';
    k%=(MOD-1);
    n%=(MOD-1);
    ll in = (k*n-n-d)%(MOD-1)+(MOD-1);
    a = ((ipow(2,in)-b)%MOD+MOD)%MOD;
    b = ipow(2,in);
    cout << a << ' ' << b << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e6+3;
ll twos(ll x){
    if(x%2)
        return 0;
    return twos(x/2)+1;
}
ll mask = (1LL<<30)-1;
ll get2(ll n, ll i){
//    cout << n << ' ' << i << '\n';
    if(n <= 30)
        return  twos((1<<n)-i);
    --i;
    ll tmp = mask-i;
    return twos(tmp);

}
ll ipow(ll a, ll p){
    if(p==0)
        return 1;
    if(p==1)
        return a;
    return ipow((a*a)%MOD,p/2)*ipow(a,p%2)%MOD;
}
ll f(ll n, ll i){
    ll tmp = twos(i);
    return ((ipow(2,n-tmp)-((i>>tmp))))%MOD;
}
int main(){
    ll n,k;
    cin >> n >> k;
    // 2^(k*n-n) - (2^n-1)!/(2^n-k)!
    // 2^(k*n-n)
    if(n <= 61 && (1LL<<n) < k){
        puts("1 1");
        return 0;
    }
    if(k > 2*MOD){
        puts("1 1");
        return 0;
    }
    ll a=1,b=1,c=1,d=0;
    for(int i = 1; i < k; ++i){
        d += get2(n,i);
    }
    // 2^(k*n-n-d) - (2^n-1)*...*(2^n-k+1)/2^d
    // 2^(k*n-n-d)
    for(int i = 1; i < k; ++i)
        b = (b*f(n,i))%MOD;
//    cout << d << '\n';
    k%=(MOD-1);
    n%=(MOD-1);
    ll in = (k*n-n-d)%(MOD-1)+(MOD-1);
    a = ((ipow(2,in)-b)%MOD+MOD)%MOD;
    b = ipow(2,in);
    cout << a << ' ' << b << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e6+3;
ll ipow(ll a, ll p){
    if(p == 0)
        return 1;
    if(p == 1)
        return a;
    return ipow(a*a%MOD,p/2)*ipow(a,p%2)%MOD;
}
ll f(ll n, ll k){
    if(k > MOD)
        return 0;
    ll ans = 1;
    for(int i = 1; i <= k; ++i)
        ans = ans * ((ipow(2,n)-i))%MOD;
    return (ans+MOD)%MOD;
}
int main(){
    // 1 - (n-1)*(n-2)*...*(n-k+1) / (n)^(k-1)
    ll n,k;
    cin >> n >> k;
    if(n < 60 && (1LL<<n) < k){
        puts("1 1");
        return 0;
    }
    --k;
    // (2^n*k)) - (2^n-1)*(2^n-2)*...*(2^n-k)
    // (2^n*k))
    ll d = 0;
    for(int i = 1; i < 60; ++i)
        d += k/(1LL<<i);
    ll c = f(n,k);
    c = (c*ipow((ipow(2,d)),MOD-2))%MOD;
    n %= (MOD-1);
    k %= (MOD-1);
    ll p = ((n*k-d)%(MOD-1)+MOD-1)%(MOD-1);
    ll a = (ipow(2,p)-c+MOD)%MOD;
    ll b = ipow(2,p);
    cout << a << ' ' << b << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e6+3;
ll twos(ll x){
    if(x%2)
        return 0;
    return twos(x/2)+1;
}
ll mask = (1LL<<30)-1;
ll get2(ll n, ll i){
//    cout << n << ' ' << i << '\n';
    if(n <= 30)
        return  twos((1<<n)-i);
    --i;
    ll tmp = mask-i;
    return twos(tmp);

}
ll ipow(ll a, ll p){
    if(p==0)
        return 1;
    if(p==1)
        return a;
    return ipow((a*a)%MOD,p/2)*ipow(a,p%2)%MOD;
}
ll f(ll n, ll i){
    ll tmp = twos(i);
    return (ipow(2,n-tmp)-(i>>tmp));
}
int main(){
    ll n,k;
    cin >> n >> k;
    // 2^(k*n-n) - (2^n-1)!/(2^n-k)!
    // 2^(k*n-n)
    if(n <= 61 && (1LL<<n) < k){
        puts("1 1");
        return 0;
    }
    if(k > MOD){
        assert(false);
        puts("1 1");
        return 0;
    }
    ll a=1,b=1,c=1,d=0;
    for(int i = 1; i < k; ++i){
        d += get2(n,i);
    }
    // 2^(k*n-n-d) - (2^n-1)*...*(2^n-k+1)/2^d
    // 2^(k*n-n-d)
    for(int i = 1; i < k; ++i)
        b = (b*f(n,i))%MOD;
//    cout << d << '\n';
    k%=(MOD-1);
    n%=(MOD-1);
    ll in = (k*n-n-d)%(MOD-1)+(MOD-1);
    a = ((ipow(2,in)-b)%MOD+MOD)%MOD;
    b = ipow(2,in);
    cout << a << ' ' << b << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e6+3;
ll twos(ll x){
    if(x%2)
        return 0;
    return twos(x/2)+1;
}
ll mask = (1LL<<30)-1;
ll get2(ll n, ll i){
//    cout << n << ' ' << i << '\n';
    if(n <= 30)
        return  twos((1<<n)-i);
    --i;
    ll tmp = mask-i;
    return twos(tmp);

}
ll ipow(ll a, ll p){
    if(p==0)
        return 1;
    if(p==1)
        return a;
    return ipow((a*a)%MOD,p/2)*ipow(a,p%2)%MOD;
}
ll f(ll n, ll i){
    ll tmp = twos(i);
    return (ipow(2,n-tmp)-(i>>tmp));
}
int main(){
    ll n,k;
    cin >> n >> k;
    // 2^(k*n-n) - (2^n-1)!/(2^n-k)!
    // 2^(k*n-n)
    if(n <= 61 && (1LL<<n) < k){
        puts("1 1");
        return 0;
    }
    k%=(MOD-1);
    n%=(MOD-1);
    if(k > 2*MOD){
        puts("1 1");
        return 0;
    }
    ll a=1,b=1,c=1,d=0;
    for(int i = 1; i < k; ++i){
        d += get2(n,i);
    }
    // 2^(k*n-n-d) - (2^n-1)*...*(2^n-k+1)/2^d
    // 2^(k*n-n-d)
    for(int i = 1; i < k; ++i)
        b = (b*f(n,i))%MOD;
//    cout << d << '\n';
    ll in = (k*n-n-d)%(MOD-1)+(MOD-1);
    a = ((ipow(2,in)-b)%MOD+MOD)%MOD;
    b = ipow(2,in);
    cout << a << ' ' << b << '\n';
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long LL ;
const int Mod = 1e6 + 3;

LL quickGCD(LL x, LL y) {
    LL ans = 1LL;
    while(y) {
        if(y & 1) {
            ans = ans * x;
            ans %= Mod;
        }
        x = (x * x) % Mod;
        y >>= 1;
    }
    return ans % Mod;
}

int main(void) {
    LL n, k;
    cin >> n >> k;
    if(n < 60 && (k >= (1 << n))) {
        cout << "1 1" << endl;
    }
    else {
        LL tmp = 0;
        LL u = k - 1;
        while(u) {
            u /= 2;
            tmp += u;
        }
        LL inv = 0;
        inv = quickGCD(2, tmp);
        inv = quickGCD(inv, 1LL * Mod-2);
        //cout << "inv " << inv << endl;
        LL num, deno;
        deno = quickGCD(2, n);
        deno = quickGCD(deno, (k-1));
        deno = (deno * inv) % Mod;
        if((k-1) >= Mod) {
            num = 0;
        }
        else {
            int u = quickGCD(2, n);
            num = 1LL;
            for(int i = 1; i < k; i ++) {
                LL t = 0;
                if(u > i) {
                    t = (u - i) % Mod;
                }
                else {
                    t = (u - i + Mod) % Mod;
                }
                num = (num * t) % Mod;
            }
            num = (num * inv) % Mod;
        }
        num = (deno - num + Mod) % Mod;
        cout << num << " " << deno << endl;
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include   <stdlib.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
ll Left[N],Right[N],dp[N][2], n, m, k, q, position[N][2], safe[N];

void Calculate()
{
	ll i, j,left = m, right = 0;
	for (j = 1; j < n + 1; j++)
	{
		left = m, right = 0;
		for (i = 0; i < k; i++)
			if (position[i][0] == j)
			{
				if (left > position[i][1])
					left = position[i][1];
				if (right < position[i][1])
					right = position[i][1];
			}
		Left[j] = left;
		Right[j] = right;
	}
}
 main()
{
	cin >> n >> m >> k >> q;
	for (int i = 0; i < k; i++)
		for (int j = 0; j < 2; j++)
			cin >> position[i][j];
	for (int i = 0; i < q; i++)
		cin >> safe[i];
	ll row,step=0;
	ll now_x = 1, now_y = 1;
	ll form_y;
	ll x2;
	ll x1;
	Calculate();
	for (row = 1; row <= n; row++)
	{
		if (row == 1)
		{
			ll nearest = N;
			ll x3;
			for (int f = 0; f < q; f++)
				if (abs(safe[f] - Right[1]) < nearest)
				{
					x3 = safe[f];
					nearest = abs(safe[f] - Right[1]);
				}

			ll minst = n;
			step += Right[1] - now_x + nearest ;
			now_x = x3;
		}
		else
		{
			int flag = 1;
			for (int g = 0; g < k&&flag != 0; g++)
				if (position[g][0] == row)
					flag = 0;
			if (flag == 0)
			{
				ll temp1,temp2;
				if (now_x >= Left[row] && now_x <= Right[row])
				{
					dp[row][0] = 2 * (Right[row] - now_x) + now_x - Left[row];
					dp[row][1] = 2 * (Left[row] - now_x) + now_x - Right[row];
				}
				else if (now_x < Left[row])
				{
					dp[row][0] = Left[row] - now_x;
					dp[row][1] = Right[row] - now_x;
				}
				else
				{
					dp[row][0] = now_x - Left[row];
					dp[row][1] = now_x - Right[row];
				}
				if (row != n)
				{
					ll nearest_1 = N;
					for (int f = 0; f < q; f++)
						if (abs(safe[f] - Left[row]) < nearest_1)
						{

							x1 = safe[f];
							nearest_1 = abs(safe[f] - Left[row]);
						}

					dp[row][0] += nearest_1;
					ll nearest_2 = N;
					for (int f = 0; f < q; f++)
						if (abs(safe[f] - Right[row]) < nearest_2)
						{
							x2 = safe[f];
							nearest_2 = abs(safe[f] - Right[row]);
						}
					dp[row][1] += nearest_2;
					if (dp[row][0] > dp[row][1] && dp[row][1] > 0)
						now_x = x2;
					else if (dp[row][0] <= dp[row][1] && dp[row][0]>0)
						now_x = x1;
				}

				step += min(dp[row][0], dp[row][1])+row-form_y;
			}
		}
		form_y = row;

	}

	printf("%d", step);
	return 0;
}


#include<stdio.h>
#include<iostream>
#include <stdlib.h>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
ll Left[N],Right[N],dp[N][2], n, m, k, q, position[N][2], safe[N];

void Calculate()
{
	ll i, j,left = m, right = 0;
	for (j = 1; j < n + 1; j++)
	{
		left = m, right = 0;
		for (i = 0; i < k; i++)
			if (position[i][0] == j)
			{
				if (left > position[i][1])
					left = position[i][1];
				if (right < position[i][1])
					right = position[i][1];
			}
		Left[j] = left;
		Right[j] = right;
	}
}
main()
{
	cin >> n >> m >> k >> q;
	for (int i = 0; i < k; i++)
		for (int j = 0; j < 2; j++)
			cin >> position[i][j];
	for (int i = 0; i < q; i++)
		cin >> safe[i];
	ll row,step=0;
	ll now_x = 1, now_y = 1;
	ll form_y;
	ll x2;
	ll x1;
	Calculate();
	for (row = 1; row <= n; row++)
	{
		if (row == 1)
		{
			ll nearest = N;
			ll x3;
			ll x4;
			x4 = lower_bound(safe, safe + q, Right[1]) - safe;
			if (abs(safe[x4] - Right[1]) < abs(safe[x4 - 1] - Right[1])&&x4>0)
			{
				nearest = abs(safe[x4] - Right[1]);
				x3 = safe[x4];
			}
			else if (x4 == 0)
			{
				nearest = abs(safe[x4] - Right[1]);
				x3 = safe[x4];
			}
			else
			{
				nearest = abs(safe[x4 - 1] - Right[1]);
				x3 = safe[x4 - 1];
			}

			step += Right[1] - now_x + nearest ;
			now_x = x3;
			form_y = row;
		}
		else
		{
			int flag = 1;
			for (int g = 0; g < k&&flag != 0; g++)
				if (position[g][0] == row)
					flag = 0;
			if (flag == 0)
			{
				ll temp1,temp2;
				if (now_x >= Left[row] && now_x <= Right[row])
				{
					dp[row][0] = 2 * (Right[row] - now_x) + now_x - Left[row];
					dp[row][1] = 2 * (now_x- Left[row] ) + Right[row]- now_x;
				}
				else if (now_x < Left[row])
				{
					dp[row][0] = Left[row] - now_x;
					dp[row][1] = Right[row] - now_x;
				}
				else
				{
					dp[row][0] = now_x - Left[row];
					dp[row][1] = now_x - Right[row];
				}
				if (row != n)
				{
					ll nearest_1 = N;
					ll x5;
					x5 = lower_bound(safe, safe + q, Left[row]) - safe;
					if (abs(safe[x5] - Left[row]) < abs(safe[x5 -1] - Left[row])&&x5>0)
					{
						nearest_1 = abs(safe[x5] - Left[row]);
						x1 = safe[x5];
					}
					else if (x5 == 0)
					{
						nearest_1 = abs(safe[x5] - Left[row]);
						x1 = safe[x5];
					}
					else
					{
						nearest_1 = abs(safe[x5 - 1] - Left[row]);
						x1 = safe[x5 -1];
					}
					dp[row][0] += nearest_1;

					ll nearest_2 = N;
					ll x6;
					x6 = lower_bound(safe, safe + q, Right[row]) - safe;
					if (abs(safe[x6] - Right[row]) < abs(safe[x6 - 1] - Right[row])&&x6>0)
					{
						nearest_2 = abs(safe[x6] - Right[row]);
						x2 = safe[x6];
					}
					else if (x6== 0)
					{
 						nearest_2 = abs(safe[x6] - Right[row]);
						x2 = safe[x6];
					}
					else
					{
						nearest_2 = abs(safe[x6 - 1] - Right[row]);
						x2 = safe[x6 - 1];
					}

					dp[row][1] += nearest_2;
					if (dp[row][0] > dp[row][1] && dp[row][1] > 0)
						now_x = x1;
					else if (dp[row][0] <= dp[row][1] && dp[row][0]>0)
						now_x = x2;
				}

				step += min(dp[row][0], dp[row][1])+row-form_y;
				form_y = row;
			}
		}

	}

	printf("%d", step);
	return 0;
}


#include<stdio.h>
#include<iostream>
#include <stdlib.h>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
ll Left[N],Right[N],dp[N][2], n, m, k, q, position[N][2], safe[N];

void Calculate()
{
	ll i, j,left = m, right = 0;
	for (j = 1; j < n + 1; j++)
	{
		left = m, right = 0;
		for (i = 0; i < k; i++)
			if (position[i][0] == j)
			{
				if (left > position[i][1])
					left = position[i][1];
				if (right < position[i][1])
					right = position[i][1];
			}
		Left[j] = left;
		Right[j] = right;
	}
}
main()
{
	cin >> n >> m >> k >> q;
	for (int i = 0; i < k; i++)
		for (int j = 0; j < 2; j++)
			cin >> position[i][j];
	for (int i = 0; i < q; i++)
		cin >> safe[i];
	ll row,step=0;
	ll now_x = 1, now_y = 1;
	ll form_y;
	ll x2;
	ll x1;
	Calculate();
		sort(safe, safe + q);
	for (row = 1; row <= n; row++)
	{
		if (row == 1)
		{
			ll nearest = N;
			ll x3;
			ll x4;
			x4 = lower_bound(safe, safe + q, Right[1]) - safe;
			if (abs(safe[x4] - Right[1]) < abs(safe[x4 - 1] - Right[1])&&x4>0)
			{
				nearest = abs(safe[x4] - Right[1]);
				x3 = safe[x4];
			}
			else if (x4 == 0)
			{
				nearest = abs(safe[x4] - Right[1]);
				x3 = safe[x4];
			}
			else
			{
				nearest = abs(safe[x4 - 1] - Right[1]);
				x3 = safe[x4 - 1];
			}

			step += Right[1] - now_x + nearest ;
			now_x = x3;
			form_y = row;
		}
		else
		{
			int flag = 1;
			for (int g = 0; g < k&&flag != 0; g++)
				if (position[g][0] == row)
					flag = 0;
			if (flag == 0)
			{
				ll temp1,temp2;
				if (now_x >= Left[row] && now_x <= Right[row])
				{
					dp[row][0] = 2 * (Right[row] - now_x) + now_x - Left[row];
					dp[row][1] = 2 * (now_x- Left[row] ) + Right[row]- now_x;
				}
				else if (now_x < Left[row])
				{
					dp[row][0] = Left[row] - now_x;
					dp[row][1] = Right[row] - now_x;
				}
				else
				{
					dp[row][0] = now_x - Left[row];
					dp[row][1] = now_x - Right[row];
				}
				if (row != n)
				{
					ll nearest_1 = N;
					ll x5;
					x5 = lower_bound(safe, safe + q, Left[row]) - safe;
					if (abs(safe[x5] - Left[row]) < abs(safe[x5 -1] - Left[row])&&x5>0)
					{
						nearest_1 = abs(safe[x5] - Left[row]);
						x1 = safe[x5];
					}
					else if (x5 == 0)
					{
						nearest_1 = abs(safe[x5] - Left[row]);
						x1 = safe[x5];
					}
					else
					{
						nearest_1 = abs(safe[x5 - 1] - Left[row]);
						x1 = safe[x5 -1];
					}
					dp[row][0] += nearest_1;

					ll nearest_2 = N;
					ll x6;
					x6 = lower_bound(safe, safe + q, Right[row]) - safe;
					if (abs(safe[x6] - Right[row]) < abs(safe[x6 - 1] - Right[row])&&x6>0)
					{
						nearest_2 = abs(safe[x6] - Right[row]);
						x2 = safe[x6];
					}
					else if (x6== 0)
					{
 						nearest_2 = abs(safe[x6] - Right[row]);
						x2 = safe[x6];
					}
					else
					{
						nearest_2 = abs(safe[x6 - 1] - Right[row]);
						x2 = safe[x6 - 1];
					}

					dp[row][1] += nearest_2;
					if (dp[row][0] > dp[row][1] && dp[row][1] > 0)
						now_x = x1;
					else if (dp[row][0] <= dp[row][1] && dp[row][0]>0)
						now_x = x2;
				}

				step += min(dp[row][0], dp[row][1])+row-form_y;
				form_y = row;
			}
		}

	}

	printf("%d", step);
	return 0;
}


#include<stdio.h>
#include<iostream>
#include   <stdlib.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
ll Left[N],Right[N],dp[N][2], n, m, k, q, position[N][2], safe[N];

void Calculate()
{
	ll i, j,left = m, right = 0;
	for (j = 1; j < n + 1; j++)
	{
		left = m, right = 0;
		for (i = 0; i < k; i++)
			if (position[i][0] == j)
			{
				if (left > position[i][1])
					left = position[i][1];
				if (right < position[i][1])
					right = position[i][1];
			}
		Left[j] = left;
		Right[j] = right;
	}
}
 main()
{
	cin >> n >> m >> k >> q;
	for (int i = 0; i < k; i++)
		for (int j = 0; j < 2; j++)
			cin >> position[i][j];
	for (int i = 0; i < q; i++)
		cin >> safe[i];
	ll row,step=0;
	ll now_x = 1, now_y = 1;
	ll form_y;
	ll x2;
	ll x1;
	Calculate();
	for (row = 1; row <= n; row++)
	{
		if (row == 1)
		{
			ll nearest = N;
			ll x3;
			for (int f = 0; f < q; f++)
				if (abs(safe[f] - Right[1]) < nearest)
				{
					x3 = safe[f];
					nearest = abs(safe[f] - Right[1]);
				}

			ll minst = n;
			step += Right[1] - now_x + nearest ;
			now_x = x3;
		}
		else
		{
			int flag = 1;
			for (int g = 0; g < k&&flag != 0; g++)
				if (position[g][0] == row)
					flag = 0;
			if (flag == 0)
			{
				ll temp1,temp2;
				if (now_x >= Left[row] && now_x <= Right[row])
				{
					dp[row][0] = 2 * (Right[row] - now_x) + now_x - Left[row];
					dp[row][1] = 2 * (now_x- Left[row] ) + Right[row]- now_x;
				}
				else if (now_x < Left[row])
				{
					dp[row][0] = Left[row] - now_x;
					dp[row][1] = Right[row] - now_x;
				}
				else
				{
					dp[row][0] = now_x - Left[row];
					dp[row][1] = now_x - Right[row];
				}
				if (row != n)
				{
					ll nearest_1 = N;
					for (int f = 0; f < q; f++)
						if (abs(safe[f] - Left[row]) < nearest_1)
						{

							x1 = safe[f];
							nearest_1 = abs(safe[f] - Left[row]);
						}

					dp[row][0] += nearest_1;
					ll nearest_2 = N;
					for (int f = 0; f < q; f++)
						if (abs(safe[f] - Right[row]) < nearest_2)
						{
							x2 = safe[f];
							nearest_2 = abs(safe[f] - Right[row]);
						}
					dp[row][1] += nearest_2;
					if (dp[row][0] > dp[row][1] && dp[row][1] > 0)
						now_x = x2;
					else if (dp[row][0] <= dp[row][1] && dp[row][0]>0)
						now_x = x1;
				}

				step += min(dp[row][0], dp[row][1])+row-form_y;
			}
		}
		form_y = row;

	}

	printf("%d", step);
	return 0;
}


#include<stdio.h>
#include<iostream>
#include   <stdlib.h>
#include<algorithm>
using namespace std;
 main()
{
	int n, m, k, q;
	cin >> n >> m >> k >> q;
	int position[200002][2], safe[200002];
	for (int i = 0; i < k; i++)
		for (int j = 0; j < 2; j++)
			cin >> position[i][j];
	for (int i = 0; i < q; i++)
		cin >> safe[i];
	int step=0;
	int i, j,start_x=1,start_y=1;
	int flag = 1,ming=100000000,location;
	for (i = 0; i < k; i++)
	{
		if (start_y == position[i][0])
			step += position[i][1] - start_x;
		else
		{
			for (j = 0; j < q; j++)
				if (safe[j] <=max(position[i][1],start_x)&&safe[j]>=min(position[i][1], start_x))
				{
					step += abs(position[i][0] - start_y) + abs(position[i][1] - start_x);
					flag = 0;
					break;
				}
			if (flag == 1)
			{
				for (j = 0; j < q; j++)
				{
					if (abs(safe[j] - start_x) < ming)
					{
						ming = abs(safe[j] - start_x);
						location = safe[j];
					}

					else if (abs(safe[j] - position[i][1]) < ming)
					{
						ming = abs(safe[j] - position[i][1]);
						location = safe[j];
					}

				}
				step += position[i][0] - start_y + abs(location - position[i][1]) + abs(location - start_x);
			}
					flag = 1;
					ming = 10000000;
		}
		start_x = position[i][1];
		start_y = position[i][0];
	}
	printf("%d", step);
	return 0;
}


#include<stdio.h>
#include<iostream>
#include <stdlib.h>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
ll Left[N],Right[N],dp[N][2], n, m, k, q, position[N][2], safe[N];

void Calculate()
{
	ll i, j,left = m, right = 0;
	for (j = 1; j < n + 1; j++)
	{
		left = m, right = 0;
		for (i = 0; i < k; i++)
			if (position[i][0] == j)
			{
				if (left > position[i][1])
					left = position[i][1];
				if (right < position[i][1])
					right = position[i][1];
			}
		Left[j] = left;
		Right[j] = right;
	}
}
main()
{
	cin >> n >> m >> k >> q;
	for (int i = 0; i < k; i++)
		for (int j = 0; j < 2; j++)
			cin >> position[i][j];
	for (int i = 0; i < q; i++)
		cin >> safe[i];
	ll row,step=0;
	ll now_x = 1, now_y = 1;
	ll form_y;
	ll x2;
	ll x1;
	Calculate();
	for (row = 1; row <= n; row++)
	{
		if (row == 1)
		{
			ll nearest = N;
			ll x3;
			ll x4;
			x4 = lower_bound(safe, safe + q, Right[1]) - safe;
			if (abs(safe[x4] - Right[1]) < abs(safe[x4 - 1] - Right[1])&&x4>0)
			{
				nearest = abs(safe[x4] - Right[1]);
				x3 = safe[x4];
			}
			else if (x4 == 0)
			{
				nearest = abs(safe[x4] - Right[1]);
				x3 = safe[x4];
			}
			else
			{
				nearest = abs(safe[x4 - 1] - Right[1]);
				x3 = safe[x4 - 1];
			}

			step += Right[1] - now_x + nearest ;
			now_x = x3;
			form_y = row;
		}
		else
		{
			int flag = 1;
			for (int g = 0; g < k&&flag != 0; g++)
				if (position[g][0] == row)
					flag = 0;
			if (flag == 0)
			{
				ll temp1,temp2;
				if (now_x >= Left[row] && now_x <= Right[row])
				{
					dp[row][0] = 2 * (Right[row] - now_x) + now_x - Left[row];
					dp[row][1] = 2 * (now_x- Left[row] ) + Right[row]- now_x;
				}
				else if (now_x < Left[row])
				{
					dp[row][0] = Left[row] - now_x;
					dp[row][1] = Right[row] - now_x;
				}
				else
				{
					dp[row][0] = now_x - Left[row];
					dp[row][1] = now_x - Right[row];
				}
				if (row != n)
				{
					ll nearest_1 = N;
					ll x5;
					x5 = lower_bound(safe, safe + q, Left[row]) - safe;
					if (abs(safe[x5] - Left[row]) < abs(safe[x5 -1] - Left[row])&&x5>0)
					{
						nearest_1 = abs(safe[x5] - Left[row]);
						x1 = safe[x5];
					}
					else if (x5 == 0)
					{
						nearest_1 = abs(safe[x5] - Left[row]);
						x1 = safe[x5];
					}
					else
					{
						nearest_1 = abs(safe[x5 - 1] - Left[row]);
						x1 = safe[x5 -1];
					}
					dp[row][0] += nearest_1;

					ll nearest_2 = N;
					ll x6;
					x6 = lower_bound(safe, safe + q, Right[row]) - safe;
					if (abs(safe[x6] - Right[row]) < abs(safe[x6 - 1] - Right[row])&&x6>0)
					{
						nearest_2 = abs(safe[x6] - Right[row]);
						x2 = safe[x6];
					}
					else if (x6== 0)
					{
 						nearest_2 = abs(safe[x6] - Right[row]);
						x1 = safe[x6];
					}
					else
					{
						nearest_2 = abs(safe[x6 - 1] - Right[row]);
						x2 = safe[x6 - 1];
					}

					dp[row][1] += nearest_2;
					if (dp[row][0] > dp[row][1] && dp[row][1] > 0)
						now_x = x1;
					else if (dp[row][0] <= dp[row][1] && dp[row][0]>0)
						now_x = x2;
				}

				step += min(dp[row][0], dp[row][1])+row-form_y;
				form_y = row;
			}
		}

	}

	printf("%d", step);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200005;

long long dp[MAXN][5];
int intrat[5], iesit[5];
int trleft[MAXN], trright[MAXN], safeleft[MAXN], saferight[MAXN];
vector<int> safe;

int calc(int lin, int entr, int exit){
    int stdr = abs(entr - trleft[lin]) + trright[lin] - trleft[lin] + abs(exit - trright[lin]);
    int drst = abs(entr - trright[lin]) + trright[lin] - trleft[lin] + abs(exit - trleft[lin]);
    return 1 + min(stdr, drst);
}

int main()
{
    int n, m, k, q;
    cin >> n >> m >> k >> q;
    for(int i = 1; i <= k; ++i){
        int x, y;
        cin >> x >> y;
        if(trleft[x] == 0) trleft[x] = y;
        trleft[x] = min(trleft[x], y);
        trright[x] = max(trright[x], y);
    }
    for(int i = 1; i <= q; ++i){
        int y;
        cin >> y;
        safe.push_back(y);
    }
    sort(safe.begin(), safe.end());
    for(int i = 0; i < (int)safe.size(); ++i){
        int st = 0, dr = 0;
        if(i > 0) st = safe[i - 1];
        dr = safe[i];
        for(int j = st; j <= dr; ++j){
            safeleft[j] = st;
            if(j > st || i == 0) saferight[j] = dr;
        }
    }
    for(int i = safe[(int)safe.size() - 1]; i <= m; ++i) safeleft[i] = safe[(int)safe.size() - 1];
    while(trleft[n] == 0) n--;
    if(n == 1){
        cout << trright[1] - 1;
        return 0;
    }
    if(trright[1] == 0){
        dp[1][2] = saferight[1] - 1;
        intrat[2] = saferight[1];
    }
    else{
        if(safeleft[trright[1]]){
            dp[1][3] = trright[1] - 1 + trright[1] - safeleft[trright[1]];
            intrat[3] = safeleft[trright[1]];
        }
        if(saferight[trleft[1]]){
            dp[1][4] = trright[1] - 1 + saferight[trright[1]] - trright[1];
            intrat[4] = saferight[trright[1]];
        }
    }
    for(int i = 2; i < n; ++i){
        if(!trright[i]){
            for(int j = 1; j <= 4; ++j) dp[i][j] = dp[i - 1][j] + 1;
            continue;
        }
        iesit[1] = safeleft[trleft[i]];
        iesit[2] = saferight[trleft[i]];
        iesit[3] = safeleft[trright[i]];
        iesit[4] = saferight[trright[i]];
        for(int j = 1; j <= 4; ++j) dp[i][j] = 1e9;
        for(int j = 1; j <= 4; ++j){
            if(intrat[j]){
                for(int k = 1; k <= 4; ++k){
                    if(iesit[k])
                        dp[i][k] = min(dp[i][k], dp[i - 1][j] + calc(i, intrat[j], iesit[k]));
                }
            }
        }
        for(int j = 1; j <= 4; ++j) intrat[j] = iesit[j];
    }
    long long ans = 1e9;
    for(int i = 1; i <= 4; ++i){
        if(intrat[i]){
            int stdr = abs(intrat[i] - trleft[n]) + trright[n] - trleft[n];
            int drst = abs(intrat[i] - trright[n]) + trright[n] - trleft[n];
            long long fin = dp[n - 1][i] + min(stdr, drst) + 1;
            ans = min(ans, fin);
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200005;

int dp[MAXN][2], trleft[MAXN], trright[MAXN], safe[MAXN];

int main()
{
    int n, m, k, q;
    cin >> n >> m >> k >> q;
    for(int i = 1; i <= n; ++i) trleft[i] = 1e9;
    int ans = 0;
    for(int i = 1; i <= k; ++i){
        int x, y;
        cin >> x >> y;
        trleft[x] = min(trleft[x], y);
        trright[x] = max(trright[x], y);
        ans = max(ans, x);
    }
    for(int i = 1; i <= q; ++i)
        cin >> safe[i];
    int colst = 1, coldr = 1;
    for(int i = 2; i <= ans; ++i){
        if(trright[i - 1] == 0) trleft[i - 1] = trright[i - 1] = coldr;
        dp[i][0] = dp[i][1] = trright[i - 1] - trleft[i - 1];
        dp[i][0] += dp[i - 1][1] + abs(trright[i - 1] - coldr);
        dp[i][1] += dp[i - 1][0] + abs(trleft[i - 1] - colst);
        int mindist = 1e9;
        for(int j = 1; j <= q; ++j){
            if(abs(trleft[i - 1] - safe[j]) < mindist){
                mindist = abs(trleft[i - 1] - safe[j]);
                colst = safe[j];
            }
        }
        dp[i][0] += mindist + 1;
        mindist = 1e9;
        for(int j = 1; j <= q; ++j){
            if(abs(trright[i - 1] - safe[j]) < mindist){
                mindist = abs(trright[i - 1] - safe[j]);
                coldr = safe[j];
            }
        }
        dp[i][1] += mindist + 1;
    }
    cout << min(dp[ans][0], dp[ans][1]) + max(trright[ans] - trleft[ans], 0) + min(max(0, abs(colst - trleft[ans])), abs(coldr - trright[ans]));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200005;

int dp[MAXN][5], intrat[5], iesit[5];
int trleft[MAXN], trright[MAXN], safeleft[MAXN], saferight[MAXN];
vector<int> safe;

int calc(int lin, int entr, int exit){
    int stdr = abs(entr - trleft[lin]) + trright[lin] - trleft[lin] + abs(exit - trright[lin]);
    int drst = abs(entr - trright[lin]) + trright[lin] - trleft[lin] + abs(exit - trleft[lin]);
    return 1 + min(stdr, drst);
}

int main()
{
    int n, m, k, q;
    cin >> n >> m >> k >> q;
    for(int i = 1; i <= k; ++i){
        int x, y;
        cin >> x >> y;
        if(trleft[x] == 0) trleft[x] = y;
        trleft[x] = min(trleft[x], y);
        trright[x] = max(trright[x], y);
    }
    for(int i = 1; i <= q; ++i){
        int y;
        cin >> y;
        safe.push_back(y);
    }
    sort(safe.begin(), safe.end());
    for(int i = 0; i < (int)safe.size(); ++i){
        int st = 0, dr = 0;
        if(i > 0) st = safe[i - 1];
        dr = safe[i];
        for(int j = st; j <= dr; ++j){
            safeleft[j] = st;
            if(j > st) saferight[j] = dr;
        }
    }
    for(int i = safe[(int)safe.size() - 1]; i <= n; ++i) safeleft[i] = safe[(int)safe.size() - 1];
    while(trleft[n] == 0) n--;
    if(n == 1){
        cout << trright[1] - 1;
        return 0;
    }
    if(trright[1] == 0){
        dp[1][1] = saferight[1] - 1;
        intrat[1] = saferight[1];
    }
    else{
        if(safeleft[trright[1]]){
            dp[1][1] = trright[1] - 1 + trright[1] - safeleft[trright[1]];
            intrat[1] = safeleft[trright[1]];
        }
        if(saferight[trleft[1]]){
            dp[1][2] =  trright[1] - 1 + saferight[trright[1]] - trright[1];
            intrat[2] = saferight[trright[1]];
        }
    }
    for(int i = 2; i < n; ++i){
        if(!trright[i]){
            for(int j = 1; j <= 4; ++j) dp[i][j] = dp[i - 1][j] + 1;
            continue;
        }
        iesit[1] = safeleft[trleft[i]];
        iesit[2] = saferight[trleft[i]];
        iesit[3] = safeleft[trright[i]];
        iesit[4] = saferight[trright[i]];
        for(int j = 1; j <= 4; ++j) dp[i][j] = 1e9;
        for(int j = 1; j <= 4; ++j){
            if(intrat[j]){
                for(int k = 1; k <= 4; ++k){
                    if(iesit[k])
                        dp[i][k] = min(dp[i][k], dp[i - 1][j] + calc(i, intrat[j], iesit[k]));
                }
            }
        }
        for(int j = 1; j <= 4; ++j) intrat[j] = iesit[j];
    }
    int ans = 1e9;
    for(int i = 1; i <= 4; ++i){
        if(intrat[i]){
            int stdr = abs(intrat[i] - trleft[n]) + trright[n] - trleft[n];
            int drst = abs(intrat[i] - trright[n]) + trright[n] - trleft[n];
            int fin = dp[n - 1][i] + min(stdr, drst) + 1;
            ans = min(ans, fin);
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200005;

int dp[MAXN][2], trleft[MAXN], trright[MAXN], safe[MAXN];

int main()
{
    int n, m, k, q;
    cin >> n >> m >> k >> q;
    for(int i = 1; i <= n; ++i) trleft[i] = 1e9;
    for(int i = 1; i <= k; ++i){
        int x, y;
        cin >> x >> y;
        trleft[x] = min(trleft[x], y);
        trright[x] = max(trright[x], y);
    }
    for(int i = 1; i <= q; ++i)
        cin >> safe[i];
    int colst = 1, coldr = 1;
    for(int i = 2; i <= n; ++i){
        if(trright[i - 1] == 0) trleft[i - 1] = trright[i - 1] = coldr;
        dp[i][0] = dp[i][1] = trright[i - 1] - trleft[i - 1];
        dp[i][0] += abs(trright[i - 1] - coldr);
        dp[i][1] += abs(trleft[i - 1] - colst);
        int mindist = 1e9;
        for(int j = 1; j <= q; ++j){
            if(abs(trleft[i - 1] - safe[j]) < mindist){
                mindist = abs(trleft[i - 1] - safe[j]);
                colst = safe[j];
            }
        }
        dp[i][0] += mindist + 1 + dp[i - 1][1];
        mindist = 1e9;
        for(int j = 1; j <= q; ++j){
            if(abs(trright[i - 1] - safe[j]) < mindist){
                mindist = abs(trright[i - 1] - safe[j]);
                coldr = safe[j];
            }
        }
        dp[i][1] += mindist + 1 + dp[i - 1][0];
    }
    if(trright[n] > 0) cout << min(dp[n][0], dp[n][1]) + max(trright[n] - trleft[n], 0) + min(max(0, abs(colst - trleft[n])), abs(coldr - trright[n]));
    else cout << min(dp[n][0], dp[n][1]) - 1;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200005;

long long dp[MAXN][5];
int intrat[5], iesit[5];
int trleft[MAXN], trright[MAXN], safeleft[MAXN], saferight[MAXN];
vector<int> safe;

int calc(int lin, int entr, int exit){
    int stdr = abs(entr - trleft[lin]) + trright[lin] - trleft[lin] + abs(exit - trright[lin]);
    int drst = abs(entr - trright[lin]) + trright[lin] - trleft[lin] + abs(exit - trleft[lin]);
    return 1 + min(stdr, drst);
}

int main()
{
    int n, m, k, q;
    cin >> n >> m >> k >> q;
    for(int i = 1; i <= k; ++i){
        int x, y;
        cin >> x >> y;
        if(trleft[x] == 0) trleft[x] = y;
        trleft[x] = min(trleft[x], y);
        trright[x] = max(trright[x], y);
    }
    for(int i = 1; i <= q; ++i){
        int y;
        cin >> y;
        safe.push_back(y);
    }
    sort(safe.begin(), safe.end());
    for(int i = 0; i < (int)safe.size(); ++i){
        int st = 0, dr = 0;
        if(i > 0) st = safe[i - 1];
        dr = safe[i];
        for(int j = st; j <= dr; ++j){
            safeleft[j] = st;
            if(j > st || i == 0) saferight[j] = dr;
        }
    }
    for(int i = safe[(int)safe.size() - 1]; i <= m; ++i) safeleft[i] = safe[(int)safe.size() - 1];
    while(trleft[n] == 0) n--;
    if(n == 1){
        cout << trright[1] - 1;
        return 0;
    }
    if(trright[1] == 0){
        dp[1][2] = saferight[1] - 1;
        intrat[2] = saferight[1];
    }
    else{
        if(safeleft[trright[1]]){
            dp[1][3] = trright[1] - 1 + trright[1] - safeleft[trright[1]];
            intrat[3] = safeleft[trright[1]];
        }
        if(saferight[trleft[1]]){
            dp[1][4] = trright[1] - 1 + saferight[trright[1]] - trright[1];
            intrat[4] = saferight[trright[1]];
        }
    }
    for(int i = 2; i < n; ++i){
        if(!trright[i]){
            for(int j = 1; j <= 4; ++j) dp[i][j] = dp[i - 1][j] + 1;
            continue;
        }
        iesit[1] = safeleft[trleft[i]];
        iesit[2] = saferight[trleft[i]];
        iesit[3] = safeleft[trright[i]];
        iesit[4] = saferight[trright[i]];
        for(int j = 1; j <= 4; ++j) dp[i][j] = 1e18;
        for(int j = 1; j <= 4; ++j){
            if(intrat[j]){
                for(int k = 1; k <= 4; ++k){
                    if(iesit[k])
                        dp[i][k] = min(dp[i][k], dp[i - 1][j] + calc(i, intrat[j], iesit[k]));
                }
            }
        }
        for(int j = 1; j <= 4; ++j) intrat[j] = iesit[j];
    }
    long long ans = 1e18;
    for(int i = 1; i <= 4; ++i){
        if(intrat[i]){
            int stdr = abs(intrat[i] - trleft[n]) + trright[n] - trleft[n];
            int drst = abs(intrat[i] - trright[n]) + trright[n] - trleft[n];
            long long fin = dp[n - 1][i] + min(stdr, drst) + 1;
            ans = min(ans, fin);
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200005;

long long dp[MAXN][5];
int intrat[5], iesit[5];
int trleft[MAXN], trright[MAXN], safeleft[MAXN], saferight[MAXN];
vector<int> safe;

int calc(int lin, int entr, int exit){
    int stdr = abs(entr - trleft[lin]) + trright[lin] - trleft[lin] + abs(exit - trright[lin]);
    int drst = abs(entr - trright[lin]) + trright[lin] - trleft[lin] + abs(exit - trleft[lin]);
    return 1 + min(stdr, drst);
}

int main()
{
    int n, m, k, q;
    cin >> n >> m >> k >> q;
    for(int i = 1; i <= k; ++i){
        int x, y;
        cin >> x >> y;
        if(trleft[x] == 0) trleft[x] = y;
        trleft[x] = min(trleft[x], y);
        trright[x] = max(trright[x], y);
    }
    for(int i = 1; i <= q; ++i){
        int y;
        cin >> y;
        safe.push_back(y);
    }
    sort(safe.begin(), safe.end());
    for(int i = 0; i < (int)safe.size(); ++i){
        int st = 0, dr = 0;
        if(i > 0) st = safe[i - 1];
        dr = safe[i];
        for(int j = st; j <= dr; ++j){
            safeleft[j] = st;
            if(j > st) saferight[j] = dr;
        }
    }
    for(int i = safe[(int)safe.size() - 1]; i <= n; ++i) safeleft[i] = safe[(int)safe.size() - 1];
    while(trleft[n] == 0) n--;
    if(n == 1){
        cout << trright[1] - 1;
        return 0;
    }
    if(trright[1] == 0){
        dp[1][1] = saferight[1] - 1;
        intrat[1] = saferight[1];
    }
    else{
        if(safeleft[trright[1]]){
            dp[1][1] = trright[1] - 1 + trright[1] - safeleft[trright[1]];
            intrat[1] = safeleft[trright[1]];
        }
        if(saferight[trleft[1]]){
            dp[1][2] = trright[1] - 1 + saferight[trright[1]] - trright[1];
            intrat[2] = saferight[trright[1]];
        }
    }
    for(int i = 2; i < n; ++i){
        if(!trright[i]){
            for(int j = 1; j <= 4; ++j) dp[i][j] = dp[i - 1][j] + 1;
            continue;
        }
        iesit[1] = safeleft[trleft[i]];
        iesit[2] = saferight[trleft[i]];
        iesit[3] = safeleft[trright[i]];
        iesit[4] = saferight[trright[i]];
        for(int j = 1; j <= 4; ++j) dp[i][j] = 1e18;
        for(int j = 1; j <= 4; ++j){
            if(intrat[j]){
                for(int k = 1; k <= 4; ++k){
                    if(iesit[k])
                        dp[i][k] = min(dp[i][k], dp[i - 1][j] + calc(i, intrat[j], iesit[k]));
                }
            }
        }
        for(int j = 1; j <= 4; ++j) intrat[j] = iesit[j];
    }
    long long ans = 1e18;
    for(int i = 1; i <= 4; ++i){
        if(intrat[i]){
            int stdr = abs(intrat[i] - trleft[n]) + trright[n] - trleft[n];
            int drst = abs(intrat[i] - trright[n]) + trright[n] - trleft[n];
            int fin = dp[n - 1][i] + min(stdr, drst) + 1;
            ans = min(ans, fin);
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200005;

long long dp[MAXN][5];
int intrat[5], iesit[5];
int trleft[MAXN], trright[MAXN], safeleft[MAXN], saferight[MAXN];
vector<int> safe;

int calc(int lin, int entr, int exit){
    int stdr = abs(entr - trleft[lin]) + trright[lin] - trleft[lin] + abs(exit - trright[lin]);
    int drst = abs(entr - trright[lin]) + trright[lin] - trleft[lin] + abs(exit - trleft[lin]);
    return 1 + min(stdr, drst);
}

int main()
{
    int n, m, k, q;
    cin >> n >> m >> k >> q;
    for(int i = 1; i <= k; ++i){
        int x, y;
        cin >> x >> y;
        if(trleft[x] == 0) trleft[x] = y;
        trleft[x] = min(trleft[x], y);
        trright[x] = max(trright[x], y);
    }
    for(int i = 1; i <= q; ++i){
        int y;
        cin >> y;
        safe.push_back(y);
    }
    sort(safe.begin(), safe.end());
    for(int i = 0; i < (int)safe.size(); ++i){
        int st = 0, dr = 0;
        if(i > 0) st = safe[i - 1];
        dr = safe[i];
        for(int j = st; j <= dr; ++j){
            safeleft[j] = st;
            if(j > st) saferight[j] = dr;
        }
    }
    for(int i = safe[(int)safe.size() - 1]; i <= n; ++i) safeleft[i] = safe[(int)safe.size() - 1];
    while(trleft[n] == 0) n--;
    if(n == 1){
        cout << trright[1] - 1;
        return 0;
    }
    if(trright[1] == 0){
        dp[1][2] = saferight[1] - 1;
        intrat[2] = saferight[1];
    }
    else{
        if(safeleft[trright[1]]){
            dp[1][3] = trright[1] - 1 + trright[1] - safeleft[trright[1]];
            intrat[3] = safeleft[trright[1]];
        }
        if(saferight[trleft[1]]){
            dp[1][4] = trright[1] - 1 + saferight[trright[1]] - trright[1];
            intrat[4] = saferight[trright[1]];
        }
    }
    for(int i = 2; i < n; ++i){
        if(!trright[i]){
            for(int j = 1; j <= 4; ++j) dp[i][j] = dp[i - 1][j] + 1;
            continue;
        }
        iesit[1] = safeleft[trleft[i]];
        iesit[2] = saferight[trleft[i]];
        iesit[3] = safeleft[trright[i]];
        iesit[4] = saferight[trright[i]];
        for(int j = 1; j <= 4; ++j) dp[i][j] = 1e9;
        for(int j = 1; j <= 4; ++j){
            if(intrat[j]){
                for(int k = 1; k <= 4; ++k){
                    if(iesit[k])
                        dp[i][k] = min(dp[i][k], dp[i - 1][j] + calc(i, intrat[j], iesit[k]));
                }
            }
        }
        for(int j = 1; j <= 4; ++j) intrat[j] = iesit[j];
    }
    long long ans = 1e9;
    for(int i = 1; i <= 4; ++i){
        if(intrat[i]){
            int stdr = abs(intrat[i] - trleft[n]) + trright[n] - trleft[n];
            int drst = abs(intrat[i] - trright[n]) + trright[n] - trleft[n];
            long long fin = dp[n - 1][i] + min(stdr, drst) + 1;
            ans = min(ans, fin);
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200005;

int dp[MAXN][2], trleft[MAXN], trright[MAXN], safe[MAXN];

int main()
{
    int n, m, k, q;
    cin >> n >> m >> k >> q;
    for(int i = 1; i <= n; ++i) trleft[i] = 1e9;
    for(int i = 1; i <= k; ++i){
        int x, y;
        cin >> x >> y;
        trleft[x] = min(trleft[x], y);
        trright[x] = max(trright[x], y);
    }
    for(int i = 1; i <= q; ++i)
        cin >> safe[i];
    int colst = 1, coldr = 1;
    for(int i = 2; i <= n; ++i){
        if(trright[i - 1] == 0) trleft[i - 1] = trright[i - 1] = coldr;
        dp[i][0] = dp[i][1] = trright[i - 1] - trleft[i - 1];
        dp[i][0] += abs(trright[i - 1] - coldr);
        dp[i][1] += abs(trleft[i - 1] - colst);
        int mindist = 1e9;
        for(int j = 1; j <= q; ++j){
            if(abs(trleft[i - 1] - safe[j]) < mindist){
                mindist = abs(trleft[i - 1] - safe[j]);
                colst = safe[j];
            }
        }
        dp[i][0] += mindist + 1 + dp[i - 1][1];
        mindist = 1e9;
        for(int j = 1; j <= q; ++j){
            if(abs(trright[i - 1] - safe[j]) < mindist){
                mindist = abs(trright[i - 1] - safe[j]);
                coldr = safe[j];
            }
        }
        dp[i][1] += mindist + 1 + dp[i - 1][0];
    }
    cout << min(dp[n][0], dp[n][1]) + trright[n] - trleft[n] + min(abs(colst - trleft[n]), abs(coldr - trright[n]));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200005;

long long dp[MAXN][5];
int intrat[5], iesit[5];
int trleft[MAXN], trright[MAXN], safeleft[MAXN], saferight[MAXN];
vector<int> safe;

int calc(int lin, int entr, int exit){
    int stdr = abs(entr - trleft[lin]) + trright[lin] - trleft[lin] + abs(exit - trright[lin]);
    int drst = abs(entr - trright[lin]) + trright[lin] - trleft[lin] + abs(exit - trleft[lin]);
    return 1 + min(stdr, drst);
}

int main()
{
    int n, m, k, q;
    cin >> n >> m >> k >> q;
    for(int i = 1; i <= k; ++i){
        int x, y;
        cin >> x >> y;
        if(trleft[x] == 0) trleft[x] = y;
        trleft[x] = min(trleft[x], y);
        trright[x] = max(trright[x], y);
    }
    for(int i = 1; i <= q; ++i){
        int y;
        cin >> y;
        safe.push_back(y);
    }
    sort(safe.begin(), safe.end());
    for(int i = 0; i < (int)safe.size(); ++i){
        int st = 0, dr = 0;
        if(i > 0) st = safe[i - 1];
        dr = safe[i];
        for(int j = st; j <= dr; ++j){
            safeleft[j] = st;
            if(j > st) saferight[j] = dr;
        }
    }
    for(int i = safe[(int)safe.size() - 1]; i <= n; ++i) safeleft[i] = safe[(int)safe.size() - 1];
    while(trleft[n] == 0) n--;
    if(n == 1){
        cout << trright[1] - 1;
        return 0;
    }
    if(trright[1] == 0){
        dp[1][1] = saferight[1] - 1;
        intrat[1] = saferight[1];
    }
    else{
        if(safeleft[trright[1]]){
            dp[1][1] = trright[1] - 1 + trright[1] - safeleft[trright[1]];
            intrat[1] = safeleft[trright[1]];
        }
        if(saferight[trleft[1]]){
            dp[1][2] = trright[1] - 1 + saferight[trright[1]] - trright[1];
            intrat[2] = saferight[trright[1]];
        }
    }
    for(int i = 2; i < n; ++i){
        if(!trright[i]){
            for(int j = 1; j <= 4; ++j) dp[i][j] = dp[i - 1][j] + 1;
            continue;
        }
        iesit[1] = safeleft[trleft[i]];
        iesit[2] = saferight[trleft[i]];
        iesit[3] = safeleft[trright[i]];
        iesit[4] = saferight[trright[i]];
        for(int j = 1; j <= 4; ++j) dp[i][j] = 1e18;
        for(int j = 1; j <= 4; ++j){
            if(intrat[j]){
                for(int k = 1; k <= 4; ++k){
                    if(iesit[k])
                        dp[i][k] = min(dp[i][k], dp[i - 1][j] + calc(i, intrat[j], iesit[k]));
                }
            }
        }
        for(int j = 1; j <= 4; ++j) intrat[j] = iesit[j];
    }
    long long ans = 1e18;
    for(int i = 1; i <= 4; ++i){
        if(intrat[i]){
            int stdr = abs(intrat[i] - trleft[n]) + trright[n] - trleft[n];
            int drst = abs(intrat[i] - trright[n]) + trright[n] - trleft[n];
            long long fin = dp[n - 1][i] + min(stdr, drst) + 1;
            ans = min(ans, fin);
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200005;

int dp[MAXN][2], trleft[MAXN], trright[MAXN];
bool safe[MAXN];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m, k, q;
    cin >> n >> m >> k >> q;
    for(int i = 1; i <= n; ++i) trleft[i] = 1e9;
    int ans = 0;
    for(int i = 1; i <= k; ++i){
        int x, y;
        cin >> x >> y;
        trleft[x] = min(trleft[x], y);
        trright[x] = max(trright[x], y);
        ans = max(ans, x);
    }
    for(int i = 1; i <= q; ++i){
        int y;
        cin >> y;
        safe[y] = 1;
    }
    int colst = 1, coldr = 1;
    for(int i = 2; i <= ans; ++i){
        if(trright[i - 1] == 0) trleft[i - 1] = trright[i - 1] = coldr;
        dp[i][0] = dp[i][1] = trright[i - 1] - trleft[i - 1];
        dp[i][0] += dp[i - 1][1] + abs(trright[i - 1] - coldr);
        dp[i][1] += dp[i - 1][0] + abs(trleft[i - 1] - colst);
        int st, dr, mnd;
        st = dr = trleft[i - 1];
        mnd = 1e9;
        while(!safe[st] && st > 0) st--;
        while(!safe[dr] && dr <= n) dr++;
        if(mnd > trleft[i - 1] - st){
            mnd = trleft[i - 1] - st;
            colst = st;
        }
        if(mnd > dr - trleft[i - 1]){
            mnd = dr - trleft[i - 1];
            colst = dr;
        }
        dp[i][0] += mnd + 1;
        st = dr = trright[i - 1];
        mnd = 1e9;
        while(!safe[st] && st > 0) st--;
        while(!safe[dr] && dr <= n) dr++;
        if(mnd > trright[i - 1] - st){
            mnd = trright[i - 1] - st;
            coldr = st;
        }
        if(mnd > dr - trright[i - 1]){
            mnd = dr - trright[i - 1];
            coldr = dr;
        }
        dp[i][1] += mnd + 1;
    }
    cout << min(dp[ans][0], dp[ans][1]) + max(trright[ans] - trleft[ans], 0) + min(max(0, abs(colst - trleft[ans])), abs(coldr - trright[ans]));
    return 0;
}


#include <bits/stdc++.h>

#define X first
#define Y second
#define mp make_pair
#define pb pop_back
#define eb emplace_back
#define sz(v) (int) v.size()

using namespace std;

typedef long long LL;
typedef long double LD;

const int inf = 1e9;
const LL INF = 1e18;

vector <int> b;
vector <vector <int>> a;
vector <vector <int>> up;
vector <vector <LL>> dp;

bool f(int a, int b, int c, int d) {
	return a <= b && b <= c && c <= d;
}

bool f(int a, int b, int c) {
	return a <= b && b <= c;
}

void relax(LL &x, LL y) {
	x = min(x, y);
}

LL dist(int x, int y) {
	return (LL) abs(x - y);
}

void solve() {
	int n, m, k, q;
	cin >> n >> m >> k >> q;
	a.resize(n);
	n = 0;
	for (int i = 0; i < k; ++i) {
		int r, c;
		cin >> r >> c;
		n = max(n, r);
		--r, --c;
		a[r].push_back(c);
	}
	for (int r = 0; r < n; ++r) {
		sort(a[r].begin(), a[r].end());
	}
	b.resize(q);
	for (int i = 0; i < q; ++i) {
		cin >> b[i];
		--b[i];
	}
	sort(b.begin(), b.end());
	up.resize(n);
	for (int r = 0; r < n; ++r) {
		if (a[r].empty()) {
			up[r].push_back(b[0]);
			up[r].push_back(b[1]);
			up[r].push_back(b[q - 2]);
			up[r].push_back(b[q - 1]);
		} else {
			up[r].push_back(b[max(0, upper_bound(b.begin(), b.end(), a[r][0]) - b.begin() - 1)]);
			up[r].push_back(*lower_bound(b.begin(), b.end(), a[r][0]));
			up[r].push_back(b[max(0, upper_bound(b.begin(), b.end(), a[r].back()) - b.begin() - 1)]);
			up[r].push_back(*lower_bound(b.begin(), b.end(), a[r].back()));
		}
	}
	if (n == 1) {
		cout << a[0].back() << "\n";
		return;
	}
	dp.resize(n, vector <LL> (4, INF));
	for (int i = 0; i < 4; ++i) {
		if (!a[0].empty()) {
			dp[0][i] = a[0].back() + dist(a[0].back(), up[0][i]);
		} else {
			dp[0][i] = up[0][i];
		}
		++dp[0][i];
	}
	for (int r = 1; r < n - 1; ++r) {
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 4; ++j) {
				if (a[r].empty()) {
					relax(dp[r][i], dp[r - 1][j] + dist(up[r - 1][j], up[r][i]));
				} else {
					int first = a[r][0], last = a[r].back(), cur = up[r - 1][j], nxt = up[r][i];
					if (f(first, last, cur, nxt)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, nxt));
					}
					if (f(first, last, nxt, cur)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, nxt));
					}
					if (f(first, cur, last, nxt)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, nxt));
					}
					if (f(first, cur, nxt, last)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
					}
					if (f(first, nxt, last, cur)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, nxt));
					}
					if (f(first, nxt, cur, last)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, last) + dist(last, first) + dist(first, nxt));
					}
					if (f(nxt, first, last, cur)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, nxt));
					}
					if (f(nxt, cur, first, last)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, last) + dist(last, nxt));
					}
					if (f(nxt, first, cur, last)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, last) + dist(last, nxt));
					}
					if (f(cur, nxt, first, last)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, last) + dist(last, nxt));
					}
					if (f(cur, first, nxt, last)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, last) + dist(last, nxt));
					}
					if (f(cur, first, last, nxt)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, nxt));
					}
				}
			}
			dp[r][i]++;
		}
	}
	LL ans = INF;
	for (int j = 0; j < 4; ++j) {
		if (a[n - 1].empty()) {
			relax(ans, dp[n - 2][j]);
		} else {
			int first = a[n - 1][0], last = a[n - 1].back(), cur = up[n - 2][j];
			if (f(first, last, cur)) {
				relax(ans, dp[n - 2][j] + dist(cur, first));
			}
			if (f(first, cur, last)) {
				relax(ans, dp[n - 2][j] + min(dist(cur, first), dist(cur, last)) + dist(first, last));
			}
			if (f(last, first, cur)) {
				relax(ans, dp[n - 2][j] + dist(cur, last));
			}
			if (f(last, cur, first)) {
				relax(ans, dp[n - 2][j] + min(dist(cur, first), dist(cur, last)) + dist(first, last));
			}
			if (f(cur, first, last)) {
				relax(ans, dp[n - 2][j] + dist(cur, last));
			}
			if (f(cur, last, first)) {
				relax(ans, dp[n - 2][j] + dist(cur, first));
			}
		}
	}
	cout << ans << "\n";
}

signed main() {
// #define TASK ""
#if !defined(LOCAL) && defined(TASK)
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define TASK ""
#define long ll
#define float ld
#define ff first
#define ss second
#define sz(vv) (int) vv.size()

const int MAX = 2e5 + 5;
const int inf = 1e9;
const long INF = 1e18;

int b[MAX];
vector <int> a[MAX];
vector <int> up[MAX];
long dp[MAX][4];

bool f(int a, int b, int c, int d) {
	return a <= b && b <= c && c <= d;
}

bool f(int a, int b, int c) {
	return a <= b && b <= c;
}

void relax(long &x, long y) {
	x = min(x, y);
}

long dist(int x, int y) {
	return (long) abs(x - y);
}

void solve() {
	int n, m, k, q;
	cin >> n >> m >> k >> q;
	n = 0;
	for (int i = 0; i < k; ++i) {
		int r, c;
		cin >> r >> c;
		n = max(n, r);
		--r, --c;
		a[r].push_back(c);
	}
	for (int r = 0; r < n; ++r) {
		sort(a[r].begin(), a[r].end());
	}
	for (int i = 0; i < q; ++i) {
		cin >> b[i];
		--b[i];
	}
	sort(b, b + q);
	for (int r = 0; r < n; ++r) {
		if (a[r].empty()) {
			up[r].push_back(b[0]);
			up[r].push_back(b[1]);
			up[r].push_back(b[q - 2]);
			up[r].push_back(b[q - 1]);
		} else {
			up[r].push_back(b[max(0, upper_bound(b, b + q, a[r][0]) - b - 1)]);
			up[r].push_back(*lower_bound(b, b + q, a[r][0]));
			up[r].push_back(b[max(0, upper_bound(b, b + q, a[r].back()) - b - 1)]);
			up[r].push_back(*lower_bound(b, b + q, a[r].back()));
		}
	}
	if (n == 1) {
		cout << a[0].back() << "\n";
		return;
	}
	for (int i = 0; i < 4; ++i) {
		if (!a[0].empty()) {
			dp[0][i] = a[0].back() + dist(a[0].back(), up[0][i]);
		} else {
			dp[0][i] = up[0][i];
		}
		++dp[0][i];
	}
	for (int r = 1; r < n - 1; ++r) {
		for (int i = 0; i < 4; ++i) {
			dp[r][i] = INF;
			for (int j = 0; j < 4; ++j) {
				if (a[r].empty()) {
					relax(dp[r][i], dp[r - 1][j] + dist(up[r - 1][j], up[r][i]));
				} else {
					int first = a[r][0], last = a[r].back(), cur = up[r - 1][j], nxt = up[r][i];
					if (f(first, last, cur, nxt)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, nxt));
					}
					if (f(first, last, nxt, cur)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, nxt));
					}
					if (f(first, cur, last, nxt)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, nxt));
					}
					if (f(first, cur, nxt, last)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
					}
					if (f(first, nxt, last, cur)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, nxt));
					}
					if (f(first, nxt, cur, last)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
					}
					if (f(cur, first, last, nxt)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, nxt));
					}
					if (f(cur, first, nxt, last)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
					}
					if (f(cur, nxt, first, last)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
					}
					if (f(nxt, first, last, cur)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
					}
					if (f(nxt, first, cur, last)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
					}
					if (f(nxt, cur, first, last)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, last) + dist(last, nxt));
					}
					swap(first, last);
					if (f(last, first, cur, nxt)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, nxt));
					}
					if (f(last, first, nxt, cur)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, nxt));
					}
					if (f(last, cur, first, nxt)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, nxt));
					}
					if (f(last, cur, nxt, first)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
					}
					if (f(last, nxt, first, cur)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, nxt));
					}
					if (f(last, nxt, cur, first)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
					}
					if (f(cur, last, first, nxt)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, nxt));
					}
					if (f(cur, last, nxt, first)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
					}
					if (f(cur, nxt, last, first)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
					}
					if (f(nxt, last, first, cur)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
					}
					if (f(nxt, last, cur, first)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
					}
					if (f(nxt, cur, last, first)) {
						relax(dp[r][i], dp[r - 1][j] + dist(cur, last) + dist(last, nxt));
					}
				}
			}
			dp[r][i]++;
		}
	}
	long ans = INF;
	for (int j = 0; j < 4; ++j) {
		if (a[n - 1].empty()) {
			relax(ans, dp[n - 2][j]);
		} else {
			int first = a[n - 1][0], last = a[n - 1].back(), cur = up[n - 2][j];
			if (f(first, last, cur)) {
				relax(ans, dp[n - 2][j] + dist(cur, first));
			}
			if (f(first, cur, last)) {
				relax(ans, dp[n - 2][j] + dist(cur, first) + dist(first, last));
			}
			if (f(last, first, cur)) {
				relax(ans, dp[n - 2][j] + dist(cur, last));
			}
			if (f(last, cur, first)) {
				relax(ans, dp[n - 2][j] + dist(cur, first) + dist(first, last));
			}
			if (f(cur, first, last)) {
				relax(ans, dp[n - 2][j] + dist(cur, last));
			}
			if (f(cur, last, first)) {
				relax(ans, dp[n - 2][j] + dist(cur, first));
			}
		}
	}
	// for (int i = 0; i < n - 1; ++i) {
	// 	debug(dp[i], 4);
	// }
	cout << ans << "\n";
}

signed main() {
#ifndef LOCAL
	// freopen(TASK".in", "r", stdin);
	// freopen(TASK".out", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>

#define X first
#define Y second
#define mp make_pair
#define pb pop_back
#define eb emplace_back
#define sz(v) (int) v.size()

using namespace std;

typedef long long LL;
typedef long double LD;

const int inf = 1e9;
const LL INF = 1e18;

vector <int> b;
vector <vector <int>> a;
vector <vector <int>> up;
vector <vector <LL>> dp;

bool f(int a, int b, int c, int d) {
	return a <= b && b <= c && c <= d;
}

bool f(int a, int b, int c) {
	return a <= b && b <= c;
}

void relax(LL &x, LL y) {
	x = min(x, y);
}

LL dist(int x, int y) {
	return (LL) abs(x - y);
}

void solve() {
	int n, m, k, q;
	cin >> n >> m >> k >> q;
	a.resize(n);
	n = 0;
	for (int i = 0; i < k; ++i) {
		int r, c;
		cin >> r >> c;
		n = max(n, r);
		--r, --c;
		a[r].push_back(c);
	}
	for (int r = 0; r < n; ++r) {
		sort(a[r].begin(), a[r].end());
	}
	b.resize(q);
	for (int i = 0; i < q; ++i) {
		cin >> b[i];
		--b[i];
	}
	sort(b.begin(), b.end());
	up.resize(n);
	int cc = 0;
	for (int r = 0; r < n; ++r) {
		if (!a[r].empty()) {
			++cc;
			up[r].eb(b[max(0, upper_bound(b.begin(), b.end(), a[r][0]) - b.begin() - 1)]);
			up[r].eb(*lower_bound(b.begin(), b.end(), a[r][0]));
			up[r].eb(b[max(0, upper_bound(b.begin(), b.end(), a[r].back()) - b.begin() - 1)]);
			up[r].eb(*lower_bound(b.begin(), b.end(), a[r].back()));
		}
	}
	if (n == 1) {
		cout << a[0].back() << "\n";
		return;
	}
	dp.resize(n, vector <LL> (4, INF));
	int start = 0;
	while (start < n && a[start].empty()) {
		start++;
	}
	assert(start < n);
	if (cc == 1) {
		LL ans = inf;
		for (int i = 0; i < q; ++i) {
			relax(ans, b[i] + start + min(dist(b[i], a[start][0]), dist(b[i], a[start].back())) + dist(a[start][0], a[start].back()));
		}
		cout << ans << "\n";
		return;
	}
	for (int i = 0; i < 4; ++i) {
		dp[start][i] = a[start].back() + dist(a[start].back(), up[start][i]) + start;
	}
	int cnt = 1;
	for (int r = start + 1; r < n - 1; ++r) {
		if (a[r].empty()) {
			cnt++;
			continue;
		}
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 4; ++j) {
				assert(!a[r - cnt].empty());
				int first = a[r][0], last = a[r].back(), cur = up[r - cnt][j], nxt = up[r][i];
				if (f(first, last, cur, nxt)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, last, nxt, cur)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, cur, last, nxt)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, cur, nxt, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
				}
				if (f(first, nxt, last, cur)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, nxt, cur, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, first) + dist(first, nxt));
				}
				if (f(nxt, first, last, cur)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, nxt));
				}
				if (f(nxt, cur, first, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(nxt, first, cur, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, nxt, first, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, first, nxt, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, first, last, nxt)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, nxt));
				}
			}
			dp[r][i] += cnt;
		}
		cnt = 1;
	}
	LL ans = INF;
	for (int j = 0; j < 4; ++j) {
		int first = a[n - 1][0], last = a[n - 1].back(), cur = up[n - cnt - 1][j];
		if (f(first, last, cur)) {
			relax(ans, dp[n - cnt - 1][j] + dist(cur, first));
		}
		if (f(first, cur, last)) {
			relax(ans, dp[n - cnt - 1][j] + min(dist(cur, first), dist(cur, last)) + dist(first, last));
		}
		if (f(last, first, cur)) {
			relax(ans, dp[n - cnt - 1][j] + dist(cur, last));
		}
		if (f(last, cur, first)) {
			relax(ans, dp[n - cnt - 1][j] + min(dist(cur, first), dist(cur, last)) + dist(first, last));
		}
		if (f(cur, first, last)) {
			relax(ans, dp[n - cnt - 1][j] + dist(cur, last));
		}
		if (f(cur, last, first)) {
			relax(ans, dp[n - cnt - 1][j] + dist(cur, first));
		}
	}
	cout << ans + cnt << "\n";
}

signed main() {
// #define TASK ""
#if !defined(LOCAL) && defined(TASK)
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>

#define X first
#define Y second
#define mp make_pair
#define pb pop_back
#define eb emplace_back
#define sz(v) (int) v.size()

using namespace std;

typedef long long LL;
typedef long double LD;

const int inf = 1e9;
const LL INF = 1e18;

vector <int> b;
vector <vector <int>> a;
vector <vector <int>> up;
vector <vector <LL>> dp;

bool f(int a, int b, int c, int d) {
	return a <= b && b <= c && c <= d;
}

bool f(int a, int b, int c) {
	return a <= b && b <= c;
}

void relax(LL &x, LL y) {
	x = min(x, y);
}

LL dist(int x, int y) {
	return (LL) abs(x - y);
}

void solve() {
	int n, m, k, q;
	cin >> n >> m >> k >> q;
	a.resize(n);
	n = 0;
	for (int i = 0; i < k; ++i) {
		int r, c;
		cin >> r >> c;
		n = max(n, r);
		--r, --c;
		a[r].push_back(c);
	}
	for (int r = 0; r < n; ++r) {
		sort(a[r].begin(), a[r].end());
	}
	b.resize(q);
	for (int i = 0; i < q; ++i) {
		cin >> b[i];
		--b[i];
	}
	sort(b.begin(), b.end());
	up.resize(n);
	int cc = 0;
	for (int r = 0; r < n; ++r) {
		if (!a[r].empty()) {
			++cc;
			up[r].eb(b[max(0, upper_bound(b.begin(), b.end(), a[r][0]) - b.begin() - 1)]);
			up[r].eb(b[min(sz(b) - 1, lower_bound(b.begin(), b.end(), a[r][0]) - b.begin())]);
			up[r].eb(b[max(0, upper_bound(b.begin(), b.end(), a[r].back()) - b.begin() - 1)]);
			up[r].eb(b[min(sz(b) - 1, lower_bound(b.begin(), b.end(), a[r].back()) - b.begin())]);
		}
	}
	if (n == 1) {
		cout << a[0].back() << "\n";
		return;
	}
	dp.resize(n, vector <LL> (4, INF));
	int start = 0;
	while (start < n && a[start].empty()) {
		start++;
	}
	assert(start < n);
	if (cc == 1) {
		if (n == 200000) {
			exit(-1);
		}
		LL ans = inf;
		for (int i = 0; i < q; ++i) {
			relax(ans, b[i] + start + min(dist(b[i], a[start][0]), dist(b[i], a[start].back())) + dist(a[start][0], a[start].back()));
		}
		cout << ans << "\n";
		return;
	}
	for (int i = 0; i < 4; ++i) {
		dp[start][i] = a[start].back() + dist(a[start].back(), up[start][i]) + start;
	}
	int cnt = 1;
	for (int r = start + 1; r < n - 1; ++r) {
		if (a[r].empty()) {
			cnt++;
			continue;
		}
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 4; ++j) {
				assert(!a[r - cnt].empty());
				int first = a[r][0], last = a[r].back(), cur = up[r - cnt][j], nxt = up[r][i];
				if (f(first, last, cur, nxt)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, last, nxt, cur)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, cur, last, nxt)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, cur, nxt, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
				}
				if (f(first, nxt, last, cur)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, nxt, cur, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, first) + dist(first, nxt));
				}
				if (f(nxt, first, last, cur)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, nxt));
				}
				if (f(nxt, cur, first, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(nxt, first, cur, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, nxt, first, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, first, nxt, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, first, last, nxt)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, nxt));
				}
			}
			dp[r][i] += cnt;
		}
		cnt = 1;
	}
	LL ans = INF;
	for (int j = 0; j < 4; ++j) {
		int first = a[n - 1][0], last = a[n - 1].back(), cur = up[n - cnt - 1][j];
		if (f(first, last, cur)) {
			relax(ans, dp[n - cnt - 1][j] + dist(cur, first));
		}
		if (f(first, cur, last)) {
			relax(ans, dp[n - cnt - 1][j] + min(dist(cur, first), dist(cur, last)) + dist(first, last));
		}
		if (f(last, first, cur)) {
			relax(ans, dp[n - cnt - 1][j] + dist(cur, last));
		}
		if (f(last, cur, first)) {
			relax(ans, dp[n - cnt - 1][j] + min(dist(cur, first), dist(cur, last)) + dist(first, last));
		}
		if (f(cur, first, last)) {
			relax(ans, dp[n - cnt - 1][j] + dist(cur, last));
		}
		if (f(cur, last, first)) {
			relax(ans, dp[n - cnt - 1][j] + dist(cur, first));
		}
	}
	cout << ans + cnt << "\n";
}

signed main() {
// #define TASK ""
#if !defined(LOCAL) && defined(TASK)
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>

#define X first
#define Y second
#define mp make_pair
#define pb pop_back
#define eb emplace_back
#define sz(v) (int) v.size()

using namespace std;

typedef long long LL;
typedef long double LD;

const int inf = 1e9;
const LL INF = 1e18;

vector <int> b;
vector <vector <int>> a;
vector <vector <int>> up;
vector <vector <LL>> dp;

bool f(int a, int b, int c, int d) {
	return a <= b && b <= c && c <= d;
}

bool f(int a, int b, int c) {
	return a <= b && b <= c;
}

void relax(LL &x, LL y) {
	x = min(x, y);
}

LL dist(int x, int y) {
	return (LL) abs(x - y);
}

void solve() {
	int n, m, k, q;
	cin >> n >> m >> k >> q;
	a.resize(n);
	n = 0;
	for (int i = 0; i < k; ++i) {
		int r, c;
		cin >> r >> c;
		n = max(n, r);
		--r, --c;
		a[r].push_back(c);
	}
	for (int r = 0; r < n; ++r) {
		sort(a[r].begin(), a[r].end());
	}
	b.resize(q);
	for (int i = 0; i < q; ++i) {
		cin >> b[i];
		--b[i];
	}
	sort(b.begin(), b.end());
	up.resize(n);
	int cc = 0;
	for (int r = 0; r < n; ++r) {
		if (!a[r].empty()) {
			++cc;
			up[r].eb(b[max(0, upper_bound(b.begin(), b.end(), a[r][0]) - b.begin() - 1)]);
			up[r].eb(b[min(sz(b) - 1, lower_bound(b.begin(), b.end(), a[r][0]) - b.begin())]);
			up[r].eb(b[max(0, upper_bound(b.begin(), b.end(), a[r].back()) - b.begin() - 1)]);
			up[r].eb(b[min(sz(b) - 1, lower_bound(b.begin(), b.end(), a[r].back()) - b.begin())]);
		}
	}
	if (n == 1) {
		cout << a[0].back() << "\n";
		return;
	}
	dp.resize(n, vector <LL> (4, INF));
	int start = 0;
	while (start < n && a[start].empty()) {
		start++;
	}
	assert(start < n);
	if (cc == 1) {
		LL ans = INF;
		for (int i = 0; i < q; ++i) {
			relax(ans, b[i] + start + min(dist(b[i], a[start][0]), dist(b[i], a[start].back())) + dist(a[start][0], a[start].back()));
		}
		cout << ans << "\n";
		return;
	}
	if (start == 0) {
		for (int i = 0; i < 4; ++i) {
			dp[0][i] = a[0].back() + dist(a[0].back(), up[0][i]);
		}
		// print(a[0], up[0]);
	} else {
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < q; ++j) {
				int first = a[start][0], last = a[start].back(), cur = b[j], nxt = up[start][i];
				if (f(first, last, cur, nxt)) {
					relax(dp[start][i], b[j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, last, nxt, cur)) {
					relax(dp[start][i], b[j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, cur, last, nxt)) {
					relax(dp[start][i], b[j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, cur, nxt, last)) {
					relax(dp[start][i], b[j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
				}
				if (f(first, nxt, last, cur)) {
					relax(dp[start][i], b[j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, nxt, cur, last)) {
					relax(dp[start][i], b[j] + dist(cur, last) + dist(last, first) + dist(first, nxt));
				}
				if (f(nxt, first, last, cur)) {
					relax(dp[start][i], b[j] + dist(cur, nxt));
				}
				if (f(nxt, cur, first, last)) {
					relax(dp[start][i], b[j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(nxt, first, cur, last)) {
					relax(dp[start][i], b[j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, nxt, first, last)) {
					relax(dp[start][i], b[j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, first, nxt, last)) {
					relax(dp[start][i], b[j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, first, last, nxt)) {
					relax(dp[start][i], b[j] + dist(cur, nxt));
				}
			}
			dp[start][i] += start;
		}
	}
	int pred = start;
	for (int r = start + 1; r < n - 1; ++r) {
		if (a[r].empty()) {
			continue;
		}
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 4; ++j) {
				int first = a[r][0], last = a[r].back(), cur = up[pred][j], nxt = up[r][i];
				if (f(first, last, cur, nxt)) {
					relax(dp[r][i], dp[pred][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, last, nxt, cur)) {
					relax(dp[r][i], dp[pred][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, cur, last, nxt)) {
					relax(dp[r][i], dp[pred][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, cur, nxt, last)) {
					relax(dp[r][i], dp[pred][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
				}
				if (f(first, nxt, last, cur)) {
					relax(dp[r][i], dp[pred][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, nxt, cur, last)) {
					relax(dp[r][i], dp[pred][j] + dist(cur, last) + dist(last, first) + dist(first, nxt));
				}
				if (f(nxt, first, last, cur)) {
					relax(dp[r][i], dp[pred][j] + dist(cur, nxt));
				}
				if (f(nxt, cur, first, last)) {
					relax(dp[r][i], dp[pred][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(nxt, first, cur, last)) {
					relax(dp[r][i], dp[pred][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, nxt, first, last)) {
					relax(dp[r][i], dp[pred][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, first, nxt, last)) {
					relax(dp[r][i], dp[pred][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, first, last, nxt)) {
					relax(dp[r][i], dp[pred][j] + dist(cur, nxt));
				}
			}
			dp[r][i] += (r - pred);
		}
		pred = r;
	}
	LL ans = INF;
	for (int j = 0; j < 4; ++j) {
		int first = a[n - 1][0], last = a[n - 1].back(), cur = up[pred][j];
		if (f(first, last, cur)) {
			relax(ans, dp[pred][j] + dist(cur, first));
		}
		if (f(first, cur, last)) {
			relax(ans, dp[pred][j] + min(dist(cur, first), dist(cur, last)) + dist(first, last));
		}
		if (f(last, first, cur)) {
			relax(ans, dp[pred][j] + dist(cur, last));
		}
		if (f(last, cur, first)) {
			relax(ans, dp[pred][j] + min(dist(cur, first), dist(cur, last)) + dist(first, last));
		}
		if (f(cur, first, last)) {
			relax(ans, dp[pred][j] + dist(cur, last));
		}
		if (f(cur, last, first)) {
			relax(ans, dp[pred][j] + dist(cur, first));
		}
	}
	ans += (n - 1 - pred);
	cout << ans << "\n";
}

signed main() {
// #define TASK ""
#if !defined(LOCAL) && defined(TASK)
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>

#define X first
#define Y second
#define mp make_pair
#define pb pop_back
#define eb emplace_back
#define sz(v) (int) v.size()

using namespace std;

typedef long long LL;
typedef long double LD;

const int inf = 1e9;
const LL INF = 1e18;

vector <int> b;
vector <vector <int>> a;
vector <vector <int>> up;
vector <vector <LL>> dp;

bool f(int a, int b, int c, int d) {
	return a <= b && b <= c && c <= d;
}

bool f(int a, int b, int c) {
	return a <= b && b <= c;
}

void relax(LL &x, LL y) {
	x = min(x, y);
}

LL dist(int x, int y) {
	return (LL) abs(x - y);
}

void solve() {
	int n, m, k, q;
	cin >> n >> m >> k >> q;
	a.resize(n);
	n = 0;
	for (int i = 0; i < k; ++i) {
		int r, c;
		cin >> r >> c;
		n = max(n, r);
		--r, --c;
		a[r].push_back(c);
	}
	for (int r = 0; r < n; ++r) {
		sort(a[r].begin(), a[r].end());
	}
	b.resize(q);
	for (int i = 0; i < q; ++i) {
		cin >> b[i];
		--b[i];
	}
	sort(b.begin(), b.end());
	up.resize(n);
	int cc = 0;
	for (int r = 0; r < n; ++r) {
		if (!a[r].empty()) {
			++cc;
			up[r].eb(b[max(0, upper_bound(b.begin(), b.end(), a[r][0]) - b.begin() - 1)]);
			up[r].eb(b[min(sz(b) - 1, lower_bound(b.begin(), b.end(), a[r][0]) - b.begin())]);
			up[r].eb(b[max(0, upper_bound(b.begin(), b.end(), a[r].back()) - b.begin() - 1)]);
			up[r].eb(b[min(sz(b) - 1, lower_bound(b.begin(), b.end(), a[r].back()) - b.begin())]);
		}
	}
	if (n == 1) {
		cout << a[0].back() << "\n";
		return;
	}
	dp.resize(n, vector <LL> (4, INF));
	int start = 0;
	while (start < n && a[start].empty()) {
		start++;
	}
	assert(start < n);
	if (cc == 1) {
		LL ans = inf;
		for (int i = 0; i < q; ++i) {
			relax(ans, b[i] + start + min(dist(b[i], a[start][0]), dist(b[i], a[start].back())) + dist(a[start][0], a[start].back()));
		}
		cout << ans << "\n";
		return;
	}
	for (int i = 0; i < 4; ++i) {
		dp[start][i] = a[start].back() + dist(a[start].back(), up[start][i]) + start;
	}
	int cnt = 1;
	for (int r = start + 1; r < n - 1; ++r) {
		if (a[r].empty()) {
			cnt++;
			continue;
		}
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 4; ++j) {
				assert(!a[r - cnt].empty());
				int first = a[r][0], last = a[r].back(), cur = up[r - cnt][j], nxt = up[r][i];
				if (f(first, last, cur, nxt)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, last, nxt, cur)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, cur, last, nxt)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, cur, nxt, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, last) + dist(last, nxt));
				}
				if (f(first, nxt, last, cur)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, first) + dist(first, nxt));
				}
				if (f(first, nxt, cur, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, first) + dist(first, nxt));
				}
				if (f(nxt, first, last, cur)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, nxt));
				}
				if (f(nxt, cur, first, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(nxt, first, cur, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, nxt, first, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, first, nxt, last)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, last) + dist(last, nxt));
				}
				if (f(cur, first, last, nxt)) {
					relax(dp[r][i], dp[r - cnt][j] + dist(cur, nxt));
				}
			}
			dp[r][i] += cnt;
		}
		cnt = 1;
	}
	LL ans = INF;
	for (int j = 0; j < 4; ++j) {
		int first = a[n - 1][0], last = a[n - 1].back(), cur = up[n - cnt - 1][j];
		if (f(first, last, cur)) {
			relax(ans, dp[n - cnt - 1][j] + dist(cur, first));
		}
		if (f(first, cur, last)) {
			relax(ans, dp[n - cnt - 1][j] + min(dist(cur, first), dist(cur, last)) + dist(first, last));
		}
		if (f(last, first, cur)) {
			relax(ans, dp[n - cnt - 1][j] + dist(cur, last));
		}
		if (f(last, cur, first)) {
			relax(ans, dp[n - cnt - 1][j] + min(dist(cur, first), dist(cur, last)) + dist(first, last));
		}
		if (f(cur, first, last)) {
			relax(ans, dp[n - cnt - 1][j] + dist(cur, last));
		}
		if (f(cur, last, first)) {
			relax(ans, dp[n - cnt - 1][j] + dist(cur, first));
		}
	}
	cout << ans + cnt << "\n";
}

signed main() {
// #define TASK ""
#if !defined(LOCAL) && defined(TASK)
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		solve();
	}
	return 0;
}