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

struct BipartiteGraph
{
    int L, R;
    vector<vector<int>> adjacency_list;
    vector<int> lmatch, rmatch;

    BipartiteGraph(const int L, const int R) : L(L), R(R),
        adjacency_list(L), lmatch(L, -1), rmatch(R, -1) {}

    void add_edge(const int l, const int r) { adjacency_list[l].push_back(r); }

    int max_matching()
    {
        auto seen = vector<bool>(L);
        auto distances = vector<int>(L);
        const function<bool(int)> dfs = [&](const int l)
        {
            if (seen[l]) return false;
            else seen[l] = true;

            for (const auto r : adjacency_list[l])
            {
                const auto l2 = rmatch[r];
                if (l2 == -1 || (distances[l2] == distances[l]+1 && dfs(l2)))
                {
                    lmatch[l] = r;
                    rmatch[r] = l;
                    return true;
                }
            }
            return false;
        };

        auto result = 0;
        while (true)
        {
            const auto infinity = numeric_limits<int>::max();
            fill(begin(distances), end(distances), infinity);
            auto queue = std::queue<int>();
            for (auto l = 0; l < L; l++) if (lmatch[l] == -1)
            {
                queue.push(l);
                distances[l] = 0;
            }

            auto path_found = false;
            while (!queue.empty())
            {
                const auto l = queue.front(); queue.pop();
                for (const auto r : adjacency_list[l])
                {
                    const auto l2 = rmatch[r];
                    if (l2 == -1) path_found = true;
                    else if (distances[l2] == infinity)
                    {
                        distances[l2] = distances[l] + 1;
                        queue.push(l2);
                    }
                }
            }
            if (!path_found) break;

            fill(begin(seen), end(seen), false);
            for (auto l = 0; l < L; l++) if (lmatch[l] == -1)
                result += dfs(l);
        }
        return result;
    };
};

int main()
{
    ios::sync_with_stdio(false);

    int n, k, p;
    cin >> n >> k >> p;

    vector<int> people(n);
    for (int& x : people)
        cin >> x;

    vector<int> keys(k);
    for (int& x : keys)
        cin >> x;

    int lower = 0, upper = int(2e9);
    while (lower < upper)
    {
        int guess = lower + (upper - lower) / 2;

        BipartiteGraph graph(n, k);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < k; j++)
                if (abs(people[i]-keys[j]) + abs(keys[j]-p) <= guess)
                    graph.add_edge(i, j);

        if (graph.max_matching() == n)
            upper = guess;
        else
            lower = guess+1;
    }
    cout << lower << endl;
}


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

int main()
{
    int n, k, p;
    cin >> n >> k >> p;

    vector<int> people(n);
    for (int& x : people)
        cin >> x;

    vector<int> keys(k);
    for (int& x : keys)
        cin >> x;

    sort(begin(people), end(people));
    sort(begin(keys), end(keys));

    int lower = 0, upper = int(2e9);
    while (lower < upper)
    {
        const int guess = lower + (upper-lower) / 2;
        bool ok = true;
        for (int i = 0, j = 0; i < n; i++)
        {
            while (j < k && abs(people[i]-keys[j]) + abs(keys[j]-p) > guess)
                j++;
            if (j < k) j++;
            else ok = false;
        }
        if (ok) upper = guess;
        else lower = guess+1;
    }
    cout << lower << endl;
}


/**
*----------AC be here!----------/
* ��������������������
* ���������ߩ��������ߩ�
* ����������������������
* ����������������������
* ���������ש������ס���
* ����������������������
* �������������ߡ�������
* ����������������������
* ����������������������
* ���������������������ޱ���
* ������������������������BUG��
* ��������������������������
* �������������������������ǩ�
* ����������������������������
* �������������������ש�����
* �������������ϩϡ����ϩ�
* �������������ߩ������ߩ�
* �����������޳�û ����������by:XF*/
//�����ʮ�������
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <stack>
#include <sstream>
using namespace std;
#define LL long long
#define gcd(x,y) __gcd(x,y)
#define clr(a,b) memset(a,b,sizeof(a))
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define MAXN 2020
LL n,m,p,a[MAXN],b[MAXN];
int vis[2020];
int check(LL x)
{
	clr(vis,0);
	int k=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(vis[j]) continue;
			if(abs(a[i]-b[j])+abs(p-b[j])<=x)
			{
				vis[j]=1;
				k++;
				break;
			}
		}
		if(k==n) return 1;
		return 0;
}
int main()
{
	//freopen(".in","r",stdin);
	cin>>n>>m>>p;
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=1;i<=m;i++) scanf("%lld",&b[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	LL l=0,r=1e10,ans;
	while(l<=r)
	{
		LL m=(l+r)/2;
		if(check(m))
		{
			ans=m;
			r=m-1;
		}
		else l=m+1;
	}
	printf("%lld\n",ans);
	return 0;
}


/**
*----------AC be here!----------/
* ��������������������
* ���������ߩ��������ߩ�
* ����������������������
* ����������������������
* ���������ש������ס���
* ����������������������
* �������������ߡ�������
* ����������������������
* ����������������������
* ���������������������ޱ���
* ������������������������BUG��
* ��������������������������
* �������������������������ǩ�
* ����������������������������
* �������������������ש�����
* �������������ϩϡ����ϩ�
* �������������ߩ������ߩ�
* �����������޳�û ����������by:XF*/
//�����ʮ�������
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <stack>
#include <sstream>
using namespace std;
#define LL long long
#define gcd(x,y) __gcd(x,y)
#define clr(a,b) memset(a,b,sizeof(a))
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define MAXN 2020
LL n,m,p,a[MAXN],b[MAXN];
int vis[2020];
int check(LL x)
{
	clr(vis,0);
	int k=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
		{
			if(vis[j]) continue;
			if(abs(a[i]-b[j])+abs(p-b[j])<=x)
			{
				vis[j]=1;
				k++;
				break;
			}
		}
		if(k==n) return 1;
		return 0;
}
int main()
{
	//freopen(".in","r",stdin);
	cin>>n>>m>>p;
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);
	for(int i=0;i<m;i++) scanf("%lld",&b[i]);
	sort(a,a+n);
	sort(b,b+n);
	LL l=0,r=1e9+10,ans;
	while(l<=r)
	{
		LL m=l+(r-l)/2;
		if(check(m)) ans=m,r=m-1;
		else l=m+1;
	}
	printf("%lld\n",ans);
	return 0;
}


/**
*----------AC be here!----------/
* ��������������������
* ���������ߩ��������ߩ�
* ����������������������
* ����������������������
* ���������ש������ס���
* ����������������������
* �������������ߡ�������
* ����������������������
* ����������������������
* ���������������������ޱ���
* ������������������������BUG��
* ��������������������������
* �������������������������ǩ�
* ����������������������������
* �������������������ש�����
* �������������ϩϡ����ϩ�
* �������������ߩ������ߩ�
* �����������޳�û ����������by:XF*/
//�����ʮ�������
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <stack>
#include <sstream>
using namespace std;
#define LL long long
#define gcd(x,y) __gcd(x,y)
#define clr(a,b) memset(a,b,sizeof(a))
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define MAXN 2020
LL n,m,p,a[MAXN],b[MAXN];
int vis[2020];
int check(LL x)
{
	clr(vis,0);
	int k=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
		{
			if(vis[j]) continue;
			if(abs(a[i]-b[j])+abs(p-b[j])<=x)
			{
				vis[j]=1;
				k++;
				break;
			}
		}
		if(k==n) return 1;
		return 0;
}
int main()
{
	//freopen(".in","r",stdin);
	cin>>n>>m>>p;
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);
	for(int i=0;i<m;i++) scanf("%lld",&b[i]);
	sort(a,a+n);
	sort(b,b+n);
	LL l=0,r=1e10,ans;
	while(l<=r)
	{
		LL m=(l+r)/2;
		if(check(m))
		{
			ans=m;
			r=m-1;
		}
		else l=m+1;
	}
	printf("%lld\n",ans);
	return 0;
}


/**
*----------AC be here!----------/
* ��������������������
* ���������ߩ��������ߩ�
* ����������������������
* ����������������������
* ���������ש������ס���
* ����������������������
* �������������ߡ�������
* ����������������������
* ����������������������
* ���������������������ޱ���
* ������������������������BUG��
* ��������������������������
* �������������������������ǩ�
* ����������������������������
* �������������������ש�����
* �������������ϩϡ����ϩ�
* �������������ߩ������ߩ�
* �����������޳�û ����������by:XF*/
//�����ʮ�������
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <stack>
#include <sstream>
using namespace std;
#define LL long long
#define gcd(x,y) __gcd(x,y)
#define clr(a,b) memset(a,b,sizeof(a))
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define MAXN 2020
LL n,m,p,a[MAXN],b[MAXN];
int vis[2020];
int check(LL x)
{
	clr(vis,0);
	int k=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
		{
			if(vis[j]) continue;
			if(abs(a[i]-b[j])+abs(p-b[j])<=x)
			{
				vis[j]=1;
				k++;
				break;
			}
		}
		if(k==n) return 1;
		return 0;
}
int main()
{
	//freopen(".in","r",stdin);
	cin>>n>>m>>p;
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);
	for(int i=0;i<m;i++) scanf("%lld",&b[i]);
	sort(a,a+n);
	sort(b,b+n);
	LL l=0,r=1e9+10,ans;
	while(l<=r)
	{
		LL m=(l+r)/2;
		if(check(m)) ans=m,r=m-1;
		else l=m+1;
	}
	printf("%lld\n",ans);
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
typedef long long int ll;
typedef pair<int,int>pa;
const int N=1e5+10;
const int MOD=1e9+7;
const ll INF=1e18;
int read()
{
    int x=0;
    char ch = getchar();
    while('0'>ch||ch>'9')ch=getchar();
    while('0'<=ch&&ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return x;
}
/************************************************************/
int n,k;
ll p;
ll a[N],b[N];
ll ans;
int vis[N];
int solve(ll x)
{
    memset(vis,0,sizeof(vis));
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(vis[j]) continue;
            if(abs(a[i]-b[j])+abs(p-b[j])<=x)
            {
                vis[j]=1;
                cnt++;
                break;
            }
        }
    }
    if(cnt==n) return 1;
    return 0;
}
int main()
{
    cin>>n>>k>>p;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=k;i++) cin>>b[i];
    sort(a+1,a+1+n);
    sort(b+1,b+1+k);
    ll l=0;
    ll r=1e10;
    ans=0;
    while(r-l>=0)
    {
        ll mid=(r+l)>>1;
        if(solve(mid))
        {
            ans=mid;
            r=mid-1;
        }
        else
            l=mid+1;
    }
    cout<<ans<<endl;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

const int INF = 2e9;

int a[1000], b[2000];

int main(void) {
    int i, j, n, k, p;
    cin >> n >> k >> p;
    REP (i,n) cin >> a[i];
    REP (i,k) cin >> b[i];
    sort(a,a+n);
    sort(b,b+n);

    int ans = INF;
    REP (i,0,k-n) {
        int mx = 0;
        REP (j,n) {
            mx = max(mx,abs(b[i+j] - a[j]) + abs(p - b[i+j]));
        }
        ans = min(ans,mx);
    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

const int INF = 2e9;

int a[1000], b[2000];

int main(void) {
    int i, j, n, k, p;
    cin >> n >> k >> p;
    REP (i,n) cin >> a[i];
    REP (i,k) cin >> b[i];
    sort(a,a+n);
    sort(b,b+k);

    int ans = INF;
    REP (i,0,k-n) {
        int mx = 0;
        REP (j,n) {
            mx = max(mx,abs(b[i+j] - a[j]) + abs(p - b[i+j]));
        }
        ans = min(ans,mx);
    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

const int INF = 2e9;

int a[1000], b[2000];

int main(void) {
    int i, j, n, k, p;
    cin >> n >> k >> p;
    REP (i,n) cin >> a[i];
    REP (i,k) cin >> b[i];

    int ans = INF;
    REP (i,0,k-n) {
        int mx = 0;
        REP (j,n) {
            mx = max(mx,abs(b[i+j] - a[j]) + abs(p - b[i+j]));
        }
        ans = min(ans,mx);
    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

const int INF = 1e9;

int a[1000], b[2000];

int main(void) {
    int i, j, n, k, p;
    cin >> n >> k >> p;
    REP (i,n) cin >> a[i];
    REP (i,k) cin >> b[i];

    int ans = INF;
    REP (i,0,k-n) {
        int mn = INF;
        REP (j,n) {
            mn = min(mn,abs(b[i+j] - a[j]) + abs(p - b[i+j]));
        }
        ans = min(ans,mn);
    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

const int INF = 1e9;

int a[1000], b[2000];

int main(void) {
    int i, j, n, k, p;
    cin >> n >> k >> p;
    REP (i,n) cin >> a[i];
    REP (i,k) cin >> b[i];

    int ans = INF;
    REP (i,0,k-n) {
        int mx = 0;
        REP (j,n) {
            mx = max(mx,abs(b[i+j] - a[j]) + abs(p - b[i+j]));
        }
        ans = min(ans,mx);
    }

    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;

long long n,m,p,v[50100],ans=1e15,minn;

long long b[200100],bb[200100];

long long check(long long dis)
{
	memset(v,0,sizeof(v));
	for(int i=1,jj=1;i<=n;i++)
	{
		if(abs(bb[jj]-p)+abs(b[i]-bb[jj])<=dis&&jj<=m)
        {
            v[i]=1;
            jj++;
            continue;
        }
        while(jj<=m-1)
        {
            jj++;
            if(abs(bb[jj]-p)+abs(b[i]-bb[jj])<=dis)
            {
                v[i]=1;
                jj++;
                break;
            }
        }
	}
	for(int i=1;i<=n;i++)
		if(!v[i])
			return 0;
	return 1;
}

int main()
{
	cin>>n>>m>>p;
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=m;i++)
		cin>>bb[i];
	sort(bb+1,bb+m+1);
	sort(b+1,b+n+1);
	long long l=0,r=2e9+5000;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid))
		{
			ans=mid;
			r=mid-1;
		}
		else
			l=mid+1;
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;

long long n,m,p,v[1100],ans=1e15,minn;

vector<long long> d[2010];

long long b[1100],bb[1100];

int check(long long dis)
{
	memset(v,0,sizeof(v));
	for(int i=1,jj=1;i<=n;i++)
	{
		if(abs(bb[jj]-p)+d[jj][i-1]<=dis&&jj<=m)
        {
            v[i]=1;
            jj++;
            continue;
        }
        while(jj<=m-1)
        {
            jj++;
            if(abs(bb[jj]-p)+abs(b[i]-bb[jj])<=dis)
            {
                v[i]=1;
                jj++;
                break;
            }
        }
	}
	for(int i=1;i<=n;i++)
		if(!v[i])
			return 0;
	return 1;
}

int main()
{
	cin>>n>>m>>p;
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=m;i++)
		cin>>bb[i];
	sort(bb+1,bb+m+1);
	sort(b+1,b+n+1);
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++)
			d[i].push_back(abs(b[j]-bb[i]));
	long long l=0,r=2e9+5000;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid))
		{
			ans=mid;
			r=mid-1;
		}
		else
			l=mid+1;
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;

long long n,m,p,v[1100],ans=1e15,minn;

vector<long long> d[2010];

long long b[2100],bb[2100];

int check(long long dis)
{
	memset(v,0,sizeof(v));
	for(int i=1,jj=1;i<=n;i++)
	{
		if(abs(bb[jj]-p)+d[jj][i-1]<=dis&&jj<=m)
        {
            v[i]=1;
            jj++;
            continue;
        }
        while(jj<=m-1)
        {
            jj++;
            if(abs(bb[jj]-p)+abs(b[i]-bb[jj])<=dis)
            {
                v[i]=1;
                jj++;
                break;
            }
        }
	}
	for(int i=1;i<=n;i++)
		if(!v[i])
			return 0;
	return 1;
}

int main()
{
	cin>>n>>m>>p;
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=m;i++)
		cin>>bb[i];
	sort(bb+1,bb+m+1);
	sort(b+1,b+n+1);
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++)
			d[i].push_back(abs(b[j]-bb[i]));
	long long l=0,r=2e9+5000;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid))
		{
			ans=mid;
			r=mid-1;
		}
		else
			l=mid+1;
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;

long long n,m,p,v[1100],ans=1e15,minn;

vector<long long> d[2010];

long long b[1100],bb[1100];

int check(long long dis)
{
	memset(v,0,sizeof(v));
	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(v[j])
				continue;
			if(d[i][j]+abs(bb[i]-p)<=dis)
			{
				v[j]=1;
				break;
			}
		}
	}
	for(int i=0;i<n;i++)
		if(!v[i])
			return 0;
	return 1;
}

int main()
{
	cin>>n>>m>>p;
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=m;i++)
		cin>>bb[i];
	sort(bb+1,bb+m+1);
	sort(b+1,b+n+1);
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++)
			d[i].push_back(abs(b[j]-bb[i]));
	long long l=0,r=1e9+5000;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid))
		{
			ans=mid;
			r=mid-1;
		}
		else
			l=mid+1;
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;

long long n,m,p,v[1100],ans=1e15,minn;

vector<long long> d[2010];

long long b[2100],bb[2100];

int check(long long dis)
{
	memset(v,0,sizeof(v));
	for(int i=1,jj=1;i<=n;i++)
	{
		if(abs(bb[jj]-p)+d[jj][i-1]<=dis&&jj<=m)
        {
            v[i]=1;
            jj++;
            continue;
        }
        while(jj<=m-1)
        {
            jj++;
            if(abs(bb[jj]-p)+abs(b[i]-bb[jj])<=dis)
            {
                v[i]=1;
                jj++;
                break;
            }
        }
	}
	for(int i=1;i<=n;i++)
		if(!v[i])
			return 0;
	return 1;
}

int main()
{
	cin>>n>>m>>p;
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=m;i++)
		cin>>bb[i];
	sort(bb+1,bb+m+1);
	sort(b+1,b+n+1);
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++)
			d[i].push_back(abs(b[j]-bb[i]));
	long long l=0,r=2e9+5000;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid))
		{
			ans=mid;
			r=mid-1;
		}
		else
			l=mid+1;
	}
	cout<<ans<<endl;
	return 0;


       #pragma GCC optimize("O3")
        #pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize("unroll-loops")

        #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;

        typedef long long ll;
        typedef long double ld;
        #define int ll
        #define double ld
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define N 100001
        #define pb push_back
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        const double eps = 1e-9;

        mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());

		signed main()
		{
			int n,k,p;
			cin>>n>>k>>p;

			int a[n],b[k];
			loop(i,n)
			{
				cin>>a[i];
			}
			loop(i,k)
			{
			cin>>b[i];
			}
			sort(a,a+n);
			sort(b,b+k);
		//	loop(i,k)
		//	cout<<b[i]<<" ";
			int res=LLONG_MAX;
			loop(i,k-n)
			{
				int ans=0;
				loop(j,n)
				{
					int sum=0;
				//	cout<<b[i+j]<<endl;
					sum=abs(a[j]-b[i+j]);
					sum+=abs(p-b[i+j]);
					ans=max(ans,sum);
				}

				res=min(res,ans);
			}
			cout<<res;
		}


       #pragma GCC optimize("O3")
        #pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize("unroll-loops")

        #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;

        typedef long long ll;
        typedef long double ld;
        #define int ll
        #define double ld
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define N 100001
        #define pb push_back
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        const double eps = 1e-9;

        mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());

		signed main()
		{
			int n,k,p;
			cin>>n>>k>>p;

			int a[n],b[k];
			loop(i,n)
			{
				cin>>a[i];
			}
			loop(i,k)
			{
			cin>>b[i];
			}
			sort(a,a+n);
			sort(b,b+k);
		//	loop(i,k)
		//	cout<<b[i]<<" ";
			int res=LLONG_MAX;
			loop(i,k-n+1)
			{
				int ans=0;
				loop(j,n)
				{
					int sum=0;
				//	cout<<b[i+j]<<endl;
					sum=abs(a[j]-b[i+j]);
					sum+=abs(p-b[i+j]);
					ans=max(ans,sum);
				}

				res=min(res,ans);
			}
			cout<<res;
		}


 #pragma GCC optimize("O3")
        #pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize("unroll-loops")

        #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;

        typedef long long ll;
        typedef long double ld;
        #define int ll
        #define double ld
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define N 100001
        #define pb push_back
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        const double eps = 1e-9;

        mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());

		signed main()
		{
			int n,k,p;
			cin>>n>>k>>p;

			int a[n],b[k];
			loop(i,n)
			{
				cin>>a[i];
			}
			loop(i,k)
			{
			cin>>b[i];
			}
			sort(a,a+n);
			sort(b,b+k);
		//	loop(i,k)
		//	cout<<b[i]<<" ";
			int res=LLONG_MAX;
			loop(i,k-n+1)
			{
				int ans=0;
				loop(j,n)
				{
					int sum=0;
				//	cout<<b[i+j]<<endl;
					sum=abs(a[j]-b[i+j]);
					sum+=abs(p-b[i+j]);
					ans=max(ans,sum);
				}

				res=min(res,ans);
			}
			cout<<res;
		}


       #pragma GCC optimize("O3")
        #pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize("unroll-loops")

        #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;

        typedef long long ll;
        typedef long double ld;
        #define int ll
        #define double ld
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define N 100001
        #define pb push_back
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        const double eps = 1e-9;

        mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());

		signed main()
		{
			int n,k,p;
			cin>>n>>k>>p;

			int a[n],b[k];
			loop(i,n)
			{
				cin>>a[i];
			}
			loop(i,k)
			{
			cin>>b[i];
			}
			sort(a,a+n);
			sort(b,b+k);
		//	loop(i,k)
		//	cout<<b[i]<<" ";
			int res=INT_MAX;
			loop(i,k-n)
			{
				int ans=0;
				loop(j,n)
				{
					int sum=0;
				//	cout<<b[i+j]<<endl;
					sum=abs(a[j]-b[i+j]);
					sum+=abs(p-b[i+j]);
					ans=max(ans,sum);
				}

				res=min(res,ans);
			}
			cout<<res;
		}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<unordered_set>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2*1000 + 47;

int a[MAX];
int b[MAX];
int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);
	int n, k, p;
	cin >> n >> k >> p;
	FOR(i, 0, n) cin >> a[i];
	FOR(i, 0, k) cin >> b[i];

	sort(a, a + n);
	sort(b, b + k);
	int ans = INF;
	FOR(i, 0, k - n + 1)
	{
		int cur = 0;
		FOR(j, 0, n)
		{
			cur = max(cur, abs(a[i + j] - b[j]) + abs(b[j] - p));
		}

		ans = min(cur, ans);
	}

	cout << ans << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<unordered_set>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2 * 1000 + 47;

LL n, k, p;
LL a[MAX];
LL b[MAX];
LL mit[MAX];
bool check(LL time)
{
	FILL(mit, 0);
	FOR(i, 0, n)
	{
		LL t = -1;
		LL cur = -1;
		FOR(j, 0, k)
		{
			if (a[i] - p <= 0 && b[j] - p <= 0 && b[j] < a[i] || a[i] - p >= 0 && b[j] - p >= 0 && b[j] > a[i])
			{
				LL tempt = abs(a[i] - b[j]) + abs(b[j] - p);
				if (!mit[j] && tempt > t && tempt <= time)
				{
					cur = j;
					t = tempt;
				}
			}
		}

		if (t == -1)
		{
			LL tempd = 1000 * 1000 * 1000 * 2 + 47;
			FOR(j, 0, k)
			{
				if (a[i] - p <= 0 && b[j] - p <= 0 || a[i] - p >= 0 && b[j] - p >= 0)
				{
					LL tempt = abs(a[i] - b[j]) + abs(b[j] - p);
					if (!mit[j] && tempt > t && tempt <= time && abs(a[i] - b[j]) < tempd)
					{
						cur = j;
						t = tempt;
						tempd = abs(a[i] - b[j]);
					}
				}
			}

			if (t == -1)
			{
				FOR(j, 0, k)
				{
					LL tempt = abs(a[i] - b[j]) + abs(b[j] - p);
					if (!mit[j] && tempt > t && tempt <= time)
					{
						cur = j;
						t = tempt;
					}
				}
			}

			if (t == -1) return false;
		}

		mit[cur] = 1;
	}

	return true;
}

bool cmp(LL a, LL b)
{
	return abs(a - p) < abs(b - p);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false); cin.tie(0);

	cin >> n >> k >> p;
	FOR(i, 0, n) cin >> a[i];
	sort(a, a + n, cmp);
	FOR(i, 0, k) cin >> b[i];

	LL l = 0;
	LL r = 2 * 1000 * 1000 * 1000 + 47;
	while (r - l > 1)
	{
		LL c = (r + l) / 2;
		if (check(c))
		{
			r = c;
		}
		else
		{
			l = c;
		}
	}

	if (check(l)) r = l;
	cout << r << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<unordered_set>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2 * 1000 + 47;

int n, k, p;
int a[MAX];
int b[MAX];
int mit[MAX];
bool check(int time)
{
	FILL(mit, 0);
	FOR(i, 0, n)
	{
		int t = -1;
		int cur = -1;
		FOR(j, 0, k)
		{
			if (a[i] - p <= 0 && b[j] - p <= 0 || a[i] - p >= 0 && b[j] - p >= 0)
			{
				int tempt = abs(a[i] - b[j]) + abs(b[j] - p);
				if (!mit[j] && tempt > t && tempt <= time)
				{
					cur = j;
					t = tempt;
				}
			}
		}

		if (t == -1)
		{
			FOR(j, 0, k)
			{
				int tempt = abs(a[i] - b[j]) + abs(b[j] - p);
				if (!mit[j] && tempt > t && tempt <= time)
				{
					cur = j;
					t = tempt;
				}
			}

			if (t == -1) return false;
		}

		mit[cur] = 1;
	}

	return true;
}

bool cmp(int a, int b)
{
	return abs(a - p) < abs(b - p);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false); cin.tie(0);

	cin >> n >> k >> p;
	FOR(i, 0, n) cin >> a[i];
	sort(a, a + n, cmp);
	FOR(i, 0, k) cin >> b[i];

	int l = 0;
	int r = 2 * 1000 * 1000 * 1000 + 47;
	while (r - l > 1)
	{
		int c = (r + l) / 2;
		if (check(c))
		{
			r = c;
		}
		else
		{
			l = c;
		}
	}

	if (check(l)) r = l;
	cout << r << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<unordered_set>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2*1000 + 47;

int a[MAX];
int b[MAX];
int main()
{
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, k, p;
	cin >> n >> k >> p;
	FOR(i, 0, n) cin >> a[i];
	FOR(i, 0, k) cin >> b[i];

	sort(a, a + n);
	sort(b, b + k);
	int ans = 2 * INF;
	FOR(i, 0, k - n + 1)
	{
		int cur = 0;
		FOR(j, 0, n)
		{
			cur = max(cur, abs(a[j] - b[i + j]) + abs(b[i + j] - p));
		}

		ans = min(cur, ans);
	}

	cout << ans << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<unordered_set>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2 * 1000 + 47;

int n, k, p;
int a[MAX];
int b[MAX];
int mit[MAX];
bool check(int time)
{
	FILL(mit, 0);
	FOR(i, 0, n)
	{
		int t = -1;
		int cur = -1;
		FOR(j, 0, k)
		{
			if (a[i] - p <= 0 && b[j] - p <= 0 && b[j] < a[i] || a[i] - p >= 0 && b[j] - p >= 0 && b[j] > a[i])
			{
				int tempt = abs(a[i] - b[j]) + abs(b[j] - p);
				if (!mit[j] && tempt > t && tempt <= time)
				{
					cur = j;
					t = tempt;
				}
			}
		}

		if (t == -1)
		{
			int tempd = 1000 * 1000 * 1000 * 2 + 47;
			FOR(j, 0, k)
			{
				if (a[i] - p <= 0 && b[j] - p <= 0 || a[i] - p >= 0 && b[j] - p >= 0)
				{
					int tempt = abs(a[i] - b[j]) + abs(b[j] - p);
					if (!mit[j] && tempt > t && tempt <= time && abs(a[i] - b[j]) < tempd)
					{
						cur = j;
						t = tempt;
						tempd = abs(a[i] - b[j]);
					}
				}
			}

			if (t == -1)
			{
				FOR(j, 0, k)
				{
					int tempt = abs(a[i] - b[j]) + abs(b[j] - p);
					if (!mit[j] && tempt > t && tempt <= time)
					{
						cur = j;
						t = tempt;
					}
				}
			}

			if (t == -1) return false;
		}

		mit[cur] = 1;
	}

	return true;
}

bool cmp(int a, int b)
{
	return abs(a - p) < abs(b - p);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false); cin.tie(0);

	cin >> n >> k >> p;
	FOR(i, 0, n) cin >> a[i];
	sort(a, a + n, cmp);
	FOR(i, 0, k) cin >> b[i];

	int l = 0;
	int r = 2 * 1000 * 1000 * 1000 + 47;
	while (r - l > 1)
	{
		int c = (r + l) / 2;
		if (check(c))
		{
			r = c;
		}
		else
		{
			l = c;
		}
	}

	if (check(l)) r = l;
	cout << r << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<unordered_set>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2 * 1000 + 47;

int n, k, p;
int a[MAX];
int b[MAX];
int mit[MAX];
bool check(int time)
{
	FILL(mit, 0);
	FOR(i, 0, n)
	{
		int t = -1;
		int cur = -1;
		FOR(j, 0, k)
		{
			if (a[i] - p <= 0 && b[j] - p <= 0 || a[i] - p >= 0 && b[j] - p >= 0)
			{
				int tempt = abs(a[i] - b[j]) + abs(b[j] - p);
				if (!mit[j] && tempt > t && tempt <= time)
				{
					cur = j;
					t = tempt;
				}
			}
		}

		if (t == -1)
		{
			FOR(j, 0, k)
			{
				int tempt = abs(a[i] - b[j]) + abs(b[j] - p);
				if (!mit[j] && tempt > t && tempt <= time)
				{
					cur = j;
					t = tempt;
				}
			}

			if (t == -1) return false;
		}

		mit[cur] = 1;
	}

	return true;
}

bool cmp(int a, int b)
{
	return abs(a - p) < abs(b - p);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false); cin.tie(0);

	cin >> n >> k >> p;
	FOR(i, 0, n) cin >> a[i];
	sort(a, a + n, cmp);
	FOR(i, 0, k) cin >> b[i];

	int l = 0, r = 2 * INF;
	while (r - l > 1)
	{
		int c = (r + l) / 2;
		if (check(c))
		{
			r = c;
		}
		else
		{
			l = c;
		}
	}

	if (check(l)) r = l;
	cout << r << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<unordered_set>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2*1000 + 47;

int a[MAX];
int b[MAX];
int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);
	int n, k, p;
	cin >> n >> k >> p;
	FOR(i, 0, n) cin >> a[i];
	FOR(i, 0, k) cin >> b[i];

	sort(a, a + n);
	sort(b, b + k);
	int ans = 2 * INF;
	FOR(i, 0, k - n + 1)
	{
		int cur = 0;
		FOR(j, 0, n)
		{
			cur = max(cur, abs(a[i + j] - b[j]) + abs(b[j] - p));
		}

		ans = min(cur, ans);
	}

	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2100;
ll a[N];
ll b[N];
int n,k,p;
bool chk(ll mid){
	int now = 0;
	for(int i=1;i<=k;++i){
		if(abs(b[i]-a[now]) + abs(b[i]-p)<=mid){
			now++;
			if(now>=n)return 1;
		}
	}
	return false;
}
int main(){
	cin>>n>>k>>p;
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	for(int i=1;i<=k;++i){
		cin>>b[i];
	}
	sort(a+1,a+n+1);
	sort(b+1,b+k+1);
	ll l=0,r = 1e9;
	while(r-l>0){
		ll mid = (l+r)>>1;
		if(chk(mid))r = mid;
		else l = mid+1;
	}
	cout<<r<<"\n";
	return 0;
}


/**
    ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
        Make it happen now, not tomorrow.
        Tomorrow is a  loser's excuse.
    ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/
#ifndef _GLIbCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplu >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <cstring>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include<random>
#include <chrono>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplu >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#endif
#define __ ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
// #define INF 0x7f7f7f7f
#define ull unsigned long long int
#define pii pair<int,int>
#define ll long long int
#define ld long double
#define MSET(x,y) memset(x,y,sizeof(x))
// #define l long
#define se second
#define fi first
#define NIL 0
#define UNVISITED -1
#define EXPOLORED 0
#define mk make_pair
#define pb push_back
#define sc(n) scanf("%d",&n)
#define NIL 0
#define pii pair<int,int>
#define eps 1e-8
#define all(x) x.begin(),x.end()
#define me(u,v,w) make_pair(w,make_pair(u,v))
#define sqr(x) x*x
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define inrange(x,y,row,col) (x>=0 && y>=0 && x<row && y<col)
#define foreach(e, x) for(__typeof(x.begin()) e = x.begin(); e != x.end(); ++ e)
// #define add(a,b) (a + b >= MOD ? a+b-MOD:a+b)
#define hs(c1,c2) (256*min(c1,c2) + max(c1,c2))
typedef struct{ int sum,suf,pre,max;} Node;
int toint(const string &s) { stringstream ss; ss << s; int x; ss >> x; return x; }
const int N = 1e5+10;
const int MAXN = 3010;
const int UP = 31;
const int lim = 1e18+1;
const ll mod = 1e9+7;
const ll highest = 1e18;
// const int inf = 1e9+10;
// const double pi = 3.141592653589793238462643383;
const double pi = acos(-1);
const double Phi =  1.618033988749894;
const int logn = 20;
const double phi = 0.618033988749894;
const double root5 = 2.236067977;
/**
    ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
        Make it happen now, not tomorrow.
        Tomorrow is a loser's excuse.
    ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/
ll a[N];
ll k[N];
int n,m;
ll p;
int main(){
    cin>>n>>m>>p;
    for(int i=0;i<n;++i)cin>>a[i];
    for(int i=0;i<m;++i)cin>>k[i];
    sort(a,a+n);
    sort(k,k+m);
    ll ans = (1<<29);
    for(int j=0;j<m-n;++j){
        ll ta = 0;
        for(int i=0;i<n;++i){
            ta = max(ta,abs(a[i]-k[j+i]) + abs(p-k[j+i]));
        }
        ans = min(ans,ta);
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2100;
ll a[N];
ll b[N];
int n,k,p;
bool chk(ll mid){
	int now = 1;
	for(int i=1;i<=k;++i){
		if(abs(b[i]-a[now]) + abs(b[i]-p)<=mid){
			now++;
			if(now>n)return true;
		}
	}
	return false;
}
int main(){
	cin>>n>>k>>p;
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	for(int i=1;i<=k;++i){
		cin>>b[i];
	}
	sort(a+1,a+n+1);
	sort(b+1,b+k+1);
	ll l=0,r = 2e9,ans = 0;
	while(r-l>1){
		ll mid = (l+r)/2;
		if(chk(mid))r = mid,ans = mid;
		else l = mid+1;
	}
	cout<<r<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2100;
ll a[N];
ll b[N];
int n,k,p;
bool chk(ll mid){
	int now = 1;
	for(int i=1;i<=k;++i){
		if(abs(b[i]-a[now]) + abs(b[i]-p)<=mid){
			now++;
			if(now>n)return true;
		}
	}
	return false;
}
int main(){
	cin>>n>>k>>p;
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	for(int i=1;i<=k;++i){
		cin>>b[i];
	}
	sort(a+1,a+n+1);
	sort(b+1,b+k+1);
	ll l=0,r = 2e9,ans = 0;
	while(l<r){
		ll mid = (l+r)/2;
		if(chk(mid))r = mid,ans = mid;
		else l = mid+1;
	}
	cout<<ans<<"\n";
	return 0;
}


#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int A[1100],B[2100],n,K,p;
int check(long long lim){
	int now=1;
	for (int i=1;i<=K;i++)
		if (abs(B[i]-A[now])+abs(B[i]-p)<=lim){
			now++; if (now>n) return 1;
		}
	return 0;
}
int main(){
	scanf("%d%d%d",&n,&K,&p);
	for (int i=1;i<=n;i++) scanf("%d",&A[i]);
	for (int i=1;i<=K;i++) scanf("%d",&B[i]);
	sort(A+1,A+n+1);
	sort(B+1,B+K+1);
	long long l=0,r=2e9+10,ans=0;
	while (l<r){
		long long mid=l+r>>1;
		if (check(mid)) r=mid,ans=mid; else l=mid+1;
	}
	cout<<ans<<endl;
	return 0;
}


/**
    ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
        Make it happen now, not tomorrow.
        Tomorrow is a  loser's excuse.
    ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/
#ifndef _GLIbCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplu >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <cstring>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include<random>
#include <chrono>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplu >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#endif
#define __ ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
// #define INF 0x7f7f7f7f
#define ull unsigned long long int
#define pii pair<int,int>
#define ll long long int
#define ld long double
#define MSET(x,y) memset(x,y,sizeof(x))
// #define l long
#define se second
#define fi first
#define NIL 0
#define UNVISITED -1
#define EXPOLORED 0
#define mk make_pair
#define pb push_back
#define sc(n) scanf("%d",&n)
#define NIL 0
#define pii pair<int,int>
#define eps 1e-8
#define all(x) x.begin(),x.end()
#define me(u,v,w) make_pair(w,make_pair(u,v))
#define sqr(x) x*x
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define inrange(x,y,row,col) (x>=0 && y>=0 && x<row && y<col)
#define foreach(e, x) for(__typeof(x.begin()) e = x.begin(); e != x.end(); ++ e)
// #define add(a,b) (a + b >= MOD ? a+b-MOD:a+b)
#define hs(c1,c2) (256*min(c1,c2) + max(c1,c2))
typedef struct{ int sum,suf,pre,max;} Node;
int toint(const string &s) { stringstream ss; ss << s; int x; ss >> x; return x; }
const int N = 1e5+10;
const int MAXN = 3010;
const int UP = 31;
const int lim = 1e18+1;
const ll mod = 1e9+7;
const ll highest = 1e18;
// const int inf = 1e9+10;
// const double pi = 3.141592653589793238462643383;
const double pi = acos(-1);
const double Phi =  1.618033988749894;
const int logn = 20;
const double phi = 0.618033988749894;
const double root5 = 2.236067977;
/**
    ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
        Make it happen now, not tomorrow.
        Tomorrow is a loser's excuse.
    ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/
int a[N];
int k[N];
int n,m;
ll p;
int main(){
    cin>>n>>m>>p;
    for(int i=0;i<n;++i)scanf("%d",&a[i]);
    for(int i=0;i<m;++i)scanf("%d",&k[i]);
    sort(a,a+n);
    sort(k,k+m);
    ll ans = (1<<29);
    for(int j=0;j<m-n;++j){
        ll ta = 0;
        for(int i=0;i<n;++i){
            ta = max(ta,abs(a[i]-k[j+i]) + abs(p-k[j+i]));
        }
        ans = min(ans,ta);
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2100;
ll a[N];
ll b[N];
int n,k,p;
bool chk(ll mid){
	int now = 1;
	for(int i=1;i<=k;++i){
		if(abs(b[i]-a[now]) + abs(b[i]-p)<=mid){
			now++;
			if(now>n)return true;
		}
	}
	return false;
}
int main(){
	cin>>n>>k>>p;
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	for(int i=1;i<=k;++i){
		cin>>b[i];
	}
	sort(a+1,a+n+1);
	sort(b+1,b+k+1);
	ll l=0,r = 2e9,ans = 0;
	while(r-l>1){
		ll mid = (l+r)/2;
		if(chk(mid))r = mid,ans = mid;
		else l = mid+1;
	}
	cout<<r<<"\n";
	return 0;
}


/*
ID: temurxo1
PROG: fence
LANG: C++11
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define dout if (debug) cout
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))
#define Coder 404
typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VPI;
#define REP(i,a,n) for (int i=a;i<n;i++)
#define db(x) cerr << #x << " = " << x << endl
#define PER(i,a,n) for (int i=n-1;i>=a;i--)
const int inf = 1000000404;
const ll MOD = 1000000007ll;
const ld PI = acos(-1.0);
const ll INF = 1000000000000000404ll;
const ld EPS = 1e-9;
template <typename t1, typename t2> inline void upmax(t1 &a, t2 b) { a = max(a, (t1)b); }
template <typename t1, typename t2> inline void upmin(t1 &a, t2 b) { a = min(a, (t1)b); }
template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T>inline T lcm(T a, T b) { return a*(b / gcd(a, b)); }
template <typename T>inline T sqr(T a) { return a*a; }
inline bool pal(string &x) { int n = (int)x.length(); REP(i, 0, n / 2) { if (x[i] != x[n - i - 1]) return 0; }return 1; }
int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dx[] = { 1, 0,-1, 0 };
int dy[] = { 0, 1, 0,-1 };
int dx8[] = { 1, 1, 1, 0, 0,-1,-1,-1 };
int dy8[] = { -1, 0, 1, 1,-1,-1, 0, 1 };
int SQ = 404;
class compare{
public:
    bool operator()(const int a,const int b) const {
        return 1;
        //compare class for PQ
    }
};
template <typename T> using superset = tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
template <typename T1,typename T2> using supermap = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 123456;
#define debug 1
//**************************************************//
bool used[N];
ll n,p,k;
ll a[N];
ll b[N];
bool can(ll len) {
    REP(i,0,k) used[i]=false;
    ll ans=0;
    REP(i,0,n) {
        if (a[i]<p) {
            bool found=false,rev=false;
            REP(j,0,k) {
                if (b[j]>p) {
                    rev=true;
                    break;
                }
                if (used[j]) continue;
                ll d=abs(a[i]-b[j])+abs(b[j]-p);
                if (d<=len) {
                    found=true;
                    used[j]=true;
                    break;
                }
            }
            if (rev&&!found) {
                PER(j,0,k) {
                if (used[j]) continue;
                ll d=abs(a[i]-b[j])+abs(b[j]-p);
                if (d<=len) {
                    found=true;
                    used[j]=true;
                    break;
                }}
            }
            if (!found) return false;

        } else {

            bool found=false,rev=false;
            PER(j,0,k) {
                if (b[j]<p) {
                    rev=true;
                    break;
                }
                if (used[j]) continue;
                ll d=abs(a[i]-b[j])+abs(b[j]-p);
                if (d<=len) {
                    found=true;
                    used[j]=true;
                    break;
                }
            }
            if (rev&&!found) {
                REP(j,0,k) {
                if (used[j]) continue;
                ll d=abs(a[i]-b[j])+abs(b[j]-p);
                if (d<=len) {
                    found=true;
                    used[j]=true;
                    break;
                }
            }
            }
            if (!found) return false;
        }
    }
    return true;

}
void solve()
{
    cin>>n>>k>>p;
    REP(i,0,n) cin>>a[i];
    REP(i,0,k) cin>>b[i];
    sort(a,a+n);
    sort(b,b+k);
    ll l=0;
    ll r=INF;
    ll ans=INF;
    while (l<=r) {
        ll mid=(l+r)>>1;
        if (can(mid)) {
            upmin(ans,mid);
            r=mid-1;
        } else l=mid+1;
    }
    cout<<ans<<endl;
}
//**************************************************//
int main()
{
    //if (debug) freopen("/home/temur/Desktop/in.txt","r",stdin);
	//freopen("fence.in", "r", stdin);
	//freopen("fence.out", "w", stdout);
	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	int t = 1;
	//cin>>t;

	while (t--) {
		solve();
	};
	return 0;
}


/*
ID: temurxo1
PROG: fence
LANG: C++11
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define dout if (debug) cout
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))
#define Coder 404
typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VPI;
#define REP(i,a,n) for (int i=a;i<n;i++)
#define db(x) cerr << #x << " = " << x << endl
#define PER(i,a,n) for (int i=n-1;i>=a;i--)
const int inf = 1000000404;
const ll MOD = 1000000007ll;
const ld PI = acos(-1.0);
const ll INF = 1000000000000000404ll;
const ld EPS = 1e-9;
template <typename t1, typename t2> inline void upmax(t1 &a, t2 b) { a = max(a, (t1)b); }
template <typename t1, typename t2> inline void upmin(t1 &a, t2 b) { a = min(a, (t1)b); }
template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T>inline T lcm(T a, T b) { return a*(b / gcd(a, b)); }
template <typename T>inline T sqr(T a) { return a*a; }
inline bool pal(string &x) { int n = (int)x.length(); REP(i, 0, n / 2) { if (x[i] != x[n - i - 1]) return 0; }return 1; }
int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dx[] = { 1, 0,-1, 0 };
int dy[] = { 0, 1, 0,-1 };
int dx8[] = { 1, 1, 1, 0, 0,-1,-1,-1 };
int dy8[] = { -1, 0, 1, 1,-1,-1, 0, 1 };
int SQ = 404;
class compare{
public:
    bool operator()(const int a,const int b) const {
        return 1;
        //compare class for PQ
    }
};
template <typename T> using superset = tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
template <typename T1,typename T2> using supermap = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 123456;
#define debug 1
//**************************************************//
ll dp[2222][2222];
int a[N];
int b[N];
ll n,k,p;
ll get(int i,int j) {
    if (i==n) return 0;
    if (j==k) return INF;
    if (dp[i][j]!=-1) return dp[i][j];
    ll ans=INF;
    REP(x,j,k-(n-i-1)) {
        ll d=abs(a[i]-b[x])+abs(b[x]-p);
        ans=min(ans,max(get(i+1,x+1),d));
    }
    return (dp[i][j]=ans);
}
void solve()
{
    REP(i,0,2222)
        REP(j,0,2222) dp[i][j]=-1;
    cin>>n>>k>>p;
    REP(i,0,n) cin>>a[i];
    REP(i,0,k) cin>>b[i];
    sort(a,a+n);
    sort(b,b+k);
    cout<<get(0,0)<<endl;
}
//**************************************************//
int main()
{
    //if (debug) freopen("/home/temur/Desktop/in.txt","r",stdin);
	//freopen("fence.in", "r", stdin);
	//freopen("fence.out", "w", stdout);
	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	int t = 1;
	//cin>>t;

	while (t--) {
		solve();
	};
	return 0;
}


/*
ID: temurxo1
PROG: fence
LANG: C++11
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define dout if (debug) cout
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))
#define Coder 404
typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VPI;
#define REP(i,a,n) for (int i=a;i<n;i++)
#define db(x) cerr << #x << " = " << x << endl
#define PER(i,a,n) for (int i=n-1;i>=a;i--)
const int inf = 1000000404;
const ll MOD = 1000000007ll;
const ld PI = acos(-1.0);
const ll INF = 1000000000000000404ll;
const ld EPS = 1e-9;
template <typename t1, typename t2> inline void upmax(t1 &a, t2 b) { a = max(a, (t1)b); }
template <typename t1, typename t2> inline void upmin(t1 &a, t2 b) { a = min(a, (t1)b); }
template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T>inline T lcm(T a, T b) { return a*(b / gcd(a, b)); }
template <typename T>inline T sqr(T a) { return a*a; }
inline bool pal(string &x) { int n = (int)x.length(); REP(i, 0, n / 2) { if (x[i] != x[n - i - 1]) return 0; }return 1; }
int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dx[] = { 1, 0,-1, 0 };
int dy[] = { 0, 1, 0,-1 };
int dx8[] = { 1, 1, 1, 0, 0,-1,-1,-1 };
int dy8[] = { -1, 0, 1, 1,-1,-1, 0, 1 };
int SQ = 404;
class compare{
public:
    bool operator()(const int a,const int b) const {
        return 1;
        //compare class for PQ
    }
};
template <typename T> using superset = tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
template <typename T1,typename T2> using supermap = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 123456;
#define debug 1
//**************************************************//
bool used[N];
ll n,p,k;
ll a[N];
ll b[N];
bool can(ll len) {
    REP(i,0,k) used[i]=false;
    ll ans=0;
    REP(i,0,n) {
      //  if (a[i]<p) {
            bool found=false,rev=false;
            REP(j,0,k) {
                if (b[j]>p) {
                    rev=true;
                    break;
                }
                if (used[j]) continue;
                ll d=abs(a[i]-b[j])+abs(b[j]-p);
                if (d<=len) {
                    found=true;
                    used[j]=true;
                    break;
                }
            }
            if (rev&&!found) {
                PER(j,0,k) {
                if (used[j]) continue;
                ll d=abs(a[i]-b[j])+abs(b[j]-p);
                if (d<=len) {
                    found=true;
                    used[j]=true;
                    break;
                }}
            }
            if (!found) return false;
//
//        } else {
//
//            bool found=false,rev=false;
//            PER(j,0,k) {
//                if (b[j]<p) {
//                    rev=true;
//                    break;
//                }
//                if (used[j]) continue;
//                ll d=abs(a[i]-b[j])+abs(b[j]-p);
//                if (d<=len) {
//                    found=true;
//                    used[j]=true;
//                    break;
//                }
//            }
//            if (rev&&!found) {
//                REP(j,0,k) {
//                if (used[j]) continue;
//                ll d=abs(a[i]-b[j])+abs(b[j]-p);
//                if (d<=len) {
//                    found=true;
//                    used[j]=true;
//                    break;
//                }
//            }
//            }
//            if (!found) return false;
//        }
    }
    return true;

}
void solve()
{
    cin>>n>>k>>p;
    REP(i,0,n) cin>>a[i];
    REP(i,0,k) cin>>b[i];
    sort(a,a+n);
    sort(b,b+k);
    ll l=0;
    ll r=INF;
    ll ans=INF;
    while (l<=r) {
        ll mid=(l+r)>>1;
        if (can(mid)) {
            upmin(ans,mid);
            r=mid-1;
        } else l=mid+1;
    }
    cout<<ans<<endl;
}
//**************************************************//
int main()
{
    //if (debug) freopen("/home/temur/Desktop/in.txt","r",stdin);
	//freopen("fence.in", "r", stdin);
	//freopen("fence.out", "w", stdout);
	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	int t = 1;
	//cin>>t;

	while (t--) {
		solve();
	};
	return 0;
}


/*
ID: temurxo1
PROG: fence
LANG: C++11
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define dout if (debug) cout
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))
#define Coder 404
typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VPI;
#define REP(i,a,n) for (int i=a;i<n;i++)
#define db(x) cerr << #x << " = " << x << endl
#define PER(i,a,n) for (int i=n-1;i>=a;i--)
const int inf = 1000000404;
const ll MOD = 1000000007ll;
const ld PI = acos(-1.0);
const ll INF = 1000000000000000404ll;
const ld EPS = 1e-9;
template <typename t1, typename t2> inline void upmax(t1 &a, t2 b) { a = max(a, (t1)b); }
template <typename t1, typename t2> inline void upmin(t1 &a, t2 b) { a = min(a, (t1)b); }
template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T>inline T lcm(T a, T b) { return a*(b / gcd(a, b)); }
template <typename T>inline T sqr(T a) { return a*a; }
inline bool pal(string &x) { int n = (int)x.length(); REP(i, 0, n / 2) { if (x[i] != x[n - i - 1]) return 0; }return 1; }
int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dx[] = { 1, 0,-1, 0 };
int dy[] = { 0, 1, 0,-1 };
int dx8[] = { 1, 1, 1, 0, 0,-1,-1,-1 };
int dy8[] = { -1, 0, 1, 1,-1,-1, 0, 1 };
int SQ = 404;
class compare{
public:
    bool operator()(const int a,const int b) const {
        return 1;
        //compare class for PQ
    }
};
template <typename T> using superset = tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
template <typename T1,typename T2> using supermap = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 123456;
#define debug 1
//**************************************************//
bool used[N];
ll n,p,k;
ll a[N];
ll b[N];
bool can(ll len) {
    REP(i,0,k) used[i]=false;
    ll ans=0;
    REP(i,0,n) {
        if (a[i]<p) {
            bool found=false;
            REP(j,0,k) {
                if (used[j]) continue;
                ll d=abs(a[i]-b[j])+abs(b[j]-p);
                if (d<=len) {
                    found=true;
                    used[j]=true;
                    break;
                }
            }
            if (!found) return false;

        } else {

            bool found=false;
            PER(j,0,k) {
                if (used[j]) continue;
                ll d=abs(a[i]-b[j])+abs(b[j]-p);
                if (d<=len) {
                    found=true;
                    used[j]=true;
                    break;
                }
            }
            if (!found) return false;
        }
    }
    return true;

}
void solve()
{
    cin>>n>>k>>p;
    REP(i,0,n) cin>>a[i];
    REP(i,0,k) cin>>b[i];
    sort(a,a+n);
    sort(b,b+k);
    ll l=0;
    ll r=inf;
    ll ans=inf;
    while (l<=r) {
        ll mid=(l+r)>>1;
        if (can(mid)) {
            upmin(ans,mid);
            r=mid-1;
        } else l=mid+1;
    }
    cout<<ans<<endl;
}
//**************************************************//
int main()
{
    //if (debug) freopen("/home/temur/Desktop/in.txt","r",stdin);
	//freopen("fence.in", "r", stdin);
	//freopen("fence.out", "w", stdout);
	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	int t = 1;
	//cin>>t;

	while (t--) {
		solve();
	};
	return 0;
}


/*
ID: temurxo1
PROG: fence
LANG: C++11
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define dout if (debug) cout
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))
#define Coder 404
typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VPI;
#define REP(i,a,n) for (int i=a;i<n;i++)
#define db(x) cerr << #x << " = " << x << endl
#define PER(i,a,n) for (int i=n-1;i>=a;i--)
const int inf = 1000000404;
const ll MOD = 1000000007ll;
const ld PI = acos(-1.0);
const ll INF = 1000000000000000404ll;
const ld EPS = 1e-9;
template <typename t1, typename t2> inline void upmax(t1 &a, t2 b) { a = max(a, (t1)b); }
template <typename t1, typename t2> inline void upmin(t1 &a, t2 b) { a = min(a, (t1)b); }
template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T>inline T lcm(T a, T b) { return a*(b / gcd(a, b)); }
template <typename T>inline T sqr(T a) { return a*a; }
inline bool pal(string &x) { int n = (int)x.length(); REP(i, 0, n / 2) { if (x[i] != x[n - i - 1]) return 0; }return 1; }
int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dx[] = { 1, 0,-1, 0 };
int dy[] = { 0, 1, 0,-1 };
int dx8[] = { 1, 1, 1, 0, 0,-1,-1,-1 };
int dy8[] = { -1, 0, 1, 1,-1,-1, 0, 1 };
int SQ = 404;
class compare{
public:
    bool operator()(const int a,const int b) const {
        return 1;
        //compare class for PQ
    }
};
template <typename T> using superset = tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
template <typename T1,typename T2> using supermap = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 123456;
#define debug 1
//**************************************************//
ll dp[2222][2222];
int a[N];
int b[N];
ll n,k,p;
ll get(int i,int j) {
    if (i==n) return 0;
    if (j==k) return INF;
    if (dp[i][j]!=-1) return dp[i][j];
    ll ans=INF;
    REP(x,j,k) {
        ll d=abs(a[i]-b[x])+abs(b[x]-p);
        ans=min(ans,max(get(i+1,x+1),d));
    }
    ans=min(ans,INF);
    dp[i][j]=ans;
    return (ans);
}
void solve()
{
    REP(i,0,2222)
        REP(j,0,2222) dp[i][j]=-1;
    cin>>n>>k>>p;
    REP(i,0,n) cin>>a[i];
    REP(i,0,k) cin>>b[i];
    sort(a,a+n);
    sort(b,b+k);
    cout<<get(0,0)<<endl;
}
//**************************************************//
int main()
{
    //if (debug) freopen("/home/temur/Desktop/in.txt","r",stdin);
	//freopen("fence.in", "r", stdin);
	//freopen("fence.out", "w", stdout);
	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	int t = 1;
	//cin>>t;

	while (t--) {
		solve();
	};
	return 0;
}


/*
ID: temurxo1
PROG: fence
LANG: C++11
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define dout if (debug) cout
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))
#define Coder 404
typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VPI;
#define REP(i,a,n) for (int i=a;i<n;i++)
#define db(x) cerr << #x << " = " << x << endl
#define PER(i,a,n) for (int i=n-1;i>=a;i--)
const int inf = 1000000404;
const ll MOD = 1000000007ll;
const ld PI = acos(-1.0);
const ll INF = 1000000000000000404ll;
const ld EPS = 1e-9;
template <typename t1, typename t2> inline void upmax(t1 &a, t2 b) { a = max(a, (t1)b); }
template <typename t1, typename t2> inline void upmin(t1 &a, t2 b) { a = min(a, (t1)b); }
template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T>inline T lcm(T a, T b) { return a*(b / gcd(a, b)); }
template <typename T>inline T sqr(T a) { return a*a; }
inline bool pal(string &x) { int n = (int)x.length(); REP(i, 0, n / 2) { if (x[i] != x[n - i - 1]) return 0; }return 1; }
int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dx[] = { 1, 0,-1, 0 };
int dy[] = { 0, 1, 0,-1 };
int dx8[] = { 1, 1, 1, 0, 0,-1,-1,-1 };
int dy8[] = { -1, 0, 1, 1,-1,-1, 0, 1 };
int SQ = 404;
class compare{
public:
    bool operator()(const int a,const int b) const {
        return 1;
        //compare class for PQ
    }
};
template <typename T> using superset = tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
template <typename T1,typename T2> using supermap = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 123456;
#define debug 1
//**************************************************//
bool used[N];
ll n,p,k;
ll a[N];
ll b[N];
bool can(ll len) {
    REP(i,0,k) used[i]=false;
    ll ans=0;
    REP(i,0,n) {
        if (a[i]<p) {
            bool found=false;
            REP(j,0,k) {
                if (used[j]) continue;
                ll d=abs(a[i]-b[j])+abs(b[j]-p);
                if (d<=len) {
                    found=true;
                    used[j]=true;
                    break;
                }
            }
            if (!found) return false;

        } else {

            bool found=false;
            PER(j,0,k) {
                if (used[j]) continue;
                ll d=abs(a[i]-b[j])+abs(b[j]-p);
                if (d<=len) {
                    found=true;
                    used[j]=true;
                    break;
                }
            }
            if (!found) return false;
        }
    }
    return true;

}
void solve()
{
    cin>>n>>k>>p;
    REP(i,0,n) cin>>a[i];
    REP(i,0,k) cin>>b[i];
    sort(a,a+n);
    sort(b,b+k);
    ll l=0;
    ll r=INF;
    ll ans=INF;
    while (l<=r) {
        ll mid=(l+r)>>1;
        if (can(mid)) {
            upmin(ans,mid);
            r=mid-1;
        } else l=mid+1;
    }
    cout<<ans<<endl;
}
//**************************************************//
int main()
{
    //if (debug) freopen("/home/temur/Desktop/in.txt","r",stdin);
	//freopen("fence.in", "r", stdin);
	//freopen("fence.out", "w", stdout);
	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	int t = 1;
	//cin>>t;

	while (t--) {
		solve();
	};
	return 0;
}


/*
ID: temurxo1
PROG: fence
LANG: C++11
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define dout if (debug) cout
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))
#define Coder 404
typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VPI;
#define REP(i,a,n) for (int i=a;i<n;i++)
#define db(x) cerr << #x << " = " << x << endl
#define PER(i,a,n) for (int i=n-1;i>=a;i--)
const int inf = 1000000404;
const ll MOD = 1000000007ll;
const ld PI = acos(-1.0);
const ll INF = 1000000000000000404ll;
const ld EPS = 1e-9;
template <typename t1, typename t2> inline void upmax(t1 &a, t2 b) { a = max(a, (t1)b); }
template <typename t1, typename t2> inline void upmin(t1 &a, t2 b) { a = min(a, (t1)b); }
template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T>inline T lcm(T a, T b) { return a*(b / gcd(a, b)); }
template <typename T>inline T sqr(T a) { return a*a; }
inline bool pal(string &x) { int n = (int)x.length(); REP(i, 0, n / 2) { if (x[i] != x[n - i - 1]) return 0; }return 1; }
int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dx[] = { 1, 0,-1, 0 };
int dy[] = { 0, 1, 0,-1 };
int dx8[] = { 1, 1, 1, 0, 0,-1,-1,-1 };
int dy8[] = { -1, 0, 1, 1,-1,-1, 0, 1 };
int SQ = 404;
class compare{
public:
    bool operator()(const int a,const int b) const {
        return 1;
        //compare class for PQ
    }
};
template <typename T> using superset = tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
template <typename T1,typename T2> using supermap = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 123456;
#define debug 1
//**************************************************//
ll dp[2222][2222];
int a[N];
int b[N];
int n,k,p;
ll get(int i,int j) {
    if (i==n) return 0;
    if (j==k) return INF;
    if (dp[i][j]!=-1) return dp[i][j];
    ll ans=INF;

    REP(x,j,k) {
        ll d=abs(a[i]-b[x])+abs(b[x]-p);
        ans=min(ans,max(get(i+1,x+1),d));
    }
    return dp[i][j]=ans;
}
void solve()
{
    memset(dp,-1,sizeof(dp));
    cin>>n>>k>>p;
    REP(i,0,n) cin>>a[i];
    REP(i,0,k) cin>>b[i];
    sort(a,a+n);
    sort(b,b+n);
    cout<<get(0,0)<<endl;
}
//**************************************************//
int main()
{
    //if (debug) freopen("/home/temur/Desktop/in.txt","r",stdin);
	//freopen("fence.in", "r", stdin);
	//freopen("fence.out", "w", stdout);
	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	int t = 1;
	//cin>>t;

	while (t--) {
		solve();
	};
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, k, t, p[1010], key[2010];
int pd[1010][2010];
const int oo = 2e9;
int acha(int idp, int idk){
	if(idp==n) return 0;
	if(idk==k) return oo;
	int &res = pd[idp][idk];
	if(res != -1) return res;
	return res = min(max(abs(key[idk] - p[idp]) + abs(key[idk] - t), acha(idp+1, idk+1)), acha(idp, idk+1));
}
int32_t main(){
	scanf("%d %d %d", &n, &k, &t);
	for(int i=0; i<n; i++) scanf("%d", &p[i]);
	for(int j=0; j<k; j++) scanf("%d", &key[j]);
	sort(p,p+n);
	sort(key,key+k);
	for(int i=0; i<=n; i++) fill(pd[i], pd[i]+k+1, -1);
	printf("%d\n", acha(0,0));
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, k, t, p[1010], key[2010];
int pd[1010][2010];
const int oo = 1e13;
int acha(int idp, int idk){
	if(idp==n) return 0;
	if(idk==k) return oo;
	int &res = pd[idp][idk];
	return res = min(max(abs(key[idk] - p[idp]) + abs(key[idk] - t), acha(idp+1, idk+1)), acha(idp, idk+1));
}
int32_t main(){
	scanf("%lli %lli %lli", &n, &k, &t);
	for(int i=0; i<n; i++) scanf("%lli", &p[i]);
	for(int j=0; j<k; j++) scanf("%lli", &key[j]);
	sort(p,p+n);
	sort(key,key+k);
	memset(pd,-1,sizeof(pd));
	printf("%lli\n", acha(0,0));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, k, t, p[1010], key[2010];
int pd[1010][2010];
const int oo = 2e9;
int dist(int a, int b){
	return abs(a-b);
}
int32_t main(){
	scanf("%d %d %d", &n, &k, &t);
	for(int i=0; i<n; i++) scanf("%d", &p[i]);
	for(int j=0; j<k; j++) scanf("%d", &key[j]);
	sort(p,p+n);
	sort(key,key+k);
	//é sempre continuo
	int res = oo;
	for(int j=0; j+n-1<k; j++){
		int atu = 0;
		for(int i=0; i<n; i++){
			atu = max(atu, dist(key[i+j], p[i]) + dist(key[i+j], t));
		}
		res = min(res, atu);
	}
	printf("%d\n", res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, k, t, p[1010], key[2010];
int pd[1010][2010];
const int oo = 2e9;
int acha(int idp, int idk){
	if(idp==n) return 0;
	if(idk==k) return oo;
	int &res = pd[idp][idk];
	return res = min(max(abs(key[idk] - p[idp]) + abs(key[idk] - t), acha(idp+1, idk+1)), acha(idp, idk+1));
}
int32_t main(){
	scanf("%d %d %d", &n, &k, &t);
	for(int i=0; i<n; i++) scanf("%d", &p[i]);
	for(int j=0; j<k; j++) scanf("%d", &key[j]);
	sort(p,p+n);
	sort(key,key+k);
	for(int i=0; i<=n; i++) fill(pd[i], pd[i]+k+1, -1);
	printf("%d\n", acha(0,0));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, k, t, p[1010], key[2010];
int pd[1010][2010];
const int oo = 2e9;
int dist(int a, int b){
	return abs(a-b);
}
int32_t main(){
	scanf("%d %d %d", &n, &k, &t);
	for(int i=0; i<n; i++) scanf("%d", &p[i]);
	for(int j=0; j<k; j++) scanf("%d", &key[j]);
	sort(p,p+n);
	sort(key,key+k);
	for(int i=n; i>=0; i--){
		for(int j=k; j>=0; j--){
			if(i==n) pd[i][j] = 0;
			else if(j==k) pd[i][j] = oo;
			else{
				int pega = max(dist(key[j], p[i]) + dist(key[j], t), pd[i+1][j+1]);
				int npega = pd[i][j+1];
				pd[i][j] = min(pega, npega);
			}
		}
	}
	printf("%d\n", pd[0][0]);
	return 0;
}


#include <algorithm>
#include <iostream>

using namespace std;

const int NMAX = 1000;
const int KMAX = 2000;
const int INF = 1 << 30;

int n, k, p;
int sol = INF;
int a[1 + NMAX];
int b[1 + KMAX];

int abs(int x){
  if(x < 0)
    return -x;
  else
    return x;
}

int main()
{
  cin >> n >> k >> p;
  for(int i = 1; i <= n; i++)
    cin >> a[i];
  for(int i = 1; i <= k; i++)
    cin >> b[i];

  sort(a + 1, a + n + 1);
  sort(b + 1, b + k + 1);

  int maxx;
  for(int i = 1; i + n <= k; i++){
    maxx = 0;
    for(int j = 1; j <= n; j++){
      int pretender = abs(a[j] - b[i + j - 1]);
      pretender += abs(b[i + j - 1] - p);
      maxx = max(maxx, pretender);
    }
    sol = min(sol, maxx);
  }

  cout << sol;
  return 0;
}


#include <algorithm>
#include <iostream>

using namespace std;

const int NMAX = 1000;
const int KMAX = 2000;
const long long INF = 1000000000000;

int n, k, p;
long long sol = INF;
int a[1 + NMAX];
int b[1 + KMAX];

int abs(int x){
  if(x < 0)
    return -x;
  else
    return x;
}

int main()
{
  cin >> n >> k >> p;
  for(int i = 1; i <= n; i++)
    cin >> a[i];
  for(int i = 1; i <= k; i++)
    cin >> b[i];

  sort(a + 1, a + n + 1);
  sort(b + 1, b + k + 1);

  int maxx;
  for(int i = 1; i + n <= k + 1; i++){
    maxx = 0;
    for(int j = 1; j <= n; j++){
      int pretender = abs(a[j] - b[i + j - 1]);
      pretender += abs(b[i + j - 1] - p);
      maxx = max(maxx, pretender);
    }
    sol = min(sol, 1LL * maxx);
  }

  cout << sol;
  return 0;
}


#include <algorithm>
#include <iostream>

using namespace std;

const int NMAX = 1000;
const int KMAX = 2000;
const int INF = 1 << 30;

int n, k, p;
int sol = INF;
int a[1 + NMAX];
int b[1 + KMAX];

int abs(int x){
  if(x < 0)
    return -x;
  else
    return x;
}

int main()
{
  cin >> n >> k >> p;
  for(int i = 1; i <= n; i++)
    cin >> a[i];
  for(int i = 1; i <= k; i++)
    cin >> b[i];

  sort(a + 1, a + n + 1);
  sort(b + 1, b + p + 1);

  int maxx;
  for(int i = 1; i + n <= p; i++){
    maxx = 0;
    for(int j = 1; j <= n; j++){
      int pretender = abs(a[j] - b[i + j]);
      pretender += abs(b[i + j] - p);
      maxx = max(maxx, pretender);
    }
    sol = min(sol, maxx);
  }

  cout << sol;
  return 0;
}


#include <algorithm>
#include <iostream>

using namespace std;

const int NMAX = 1000;
const int KMAX = 2000;
const int INF = 1 << 30;

int n, k, p;
int sol = INF;
int a[1 + NMAX];
int b[1 + KMAX];

int abs(int x){
  if(x < 0)
    return -x;
  else
    return x;
}

int main()
{
  cin >> n >> k >> p;
  for(int i = 1; i <= n; i++)
    cin >> a[i];
  for(int i = 1; i <= k; i++)
    cin >> b[i];

  sort(a + 1, a + n + 1);
  sort(b + 1, b + k + 1);

  int maxx;
  for(int i = 1; i + n <= p; i++){
    maxx = 0;
    for(int j = 1; j <= n; j++){
      int pretender = abs(a[j] - b[i + j - 1]);
      pretender += abs(b[i + j - 1] - p);
      maxx = max(maxx, pretender);
    }
    sol = min(sol, maxx);
  }

  cout << sol;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=1e3+10;
int n,k;
ll a[maxn],p, b[maxn];
bool check(ll x)
{
	int item=1;
	for(int i=1;i<=n;i++)
	{
		while(item<=k&&(abs(a[i]-b[item])+abs(b[item]-p))>x)
		item++;
		if(item>k)
		return false;
		item++;
	}
	return true;
}
int main(){

	scanf("%d %d %lld",&n,&k,&p);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	for(int i=1;i<=k;i++)
	scanf("%d",&b[i]);
	sort(a+1,a+1+n);
	sort(b+1,b+1+k);
	ll  l=0,r=LONG_LONG_MAX,mid;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(check(mid))
		{
			r=mid-1;
		}
		else
		l=mid+1;
	}
	printf("%lld\n",l);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=5e3+10;
int n,k;
ll a[maxn],p, b[maxn];
bool check(ll x)
{
	int item=1;
	for(int i=1;i<=n;i++)
	{
		while(item<=k&&(abs(a[i]-b[item])+abs(b[item]-p))>x)
		item++;
		if(item>k)
		return false;
		item++;
	}
	return true;
}
int main(){

	scanf("%d %d %lld",&n,&k,&p);
	for(int i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	for(int i=1;i<=k;i++)
	scanf("%lld",&b[i]);
	sort(a+1,a+1+n);
	sort(b+1,b+1+k);
	ll  l=0,r=LONG_LONG_MAX,mid;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(check(mid))
		{
			r=mid-1;
		}
		else
		l=mid+1;
	}
	printf("%lld\n",l);
	return 0;
}


#include<bits/stdc++.h>
#define inf 0x7f3f3f3f
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=5e3+10;
int n,k;
ll p;
ll dp[maxn][maxn],a[maxn],b[maxn];
int main(){

	scanf("%d %d %lld",&n,&k,&p);
	for(int i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	for(int i=1;i<=k;i++)
	scanf("%lld",&b[i]);
	sort(a+1,a+1+n);
	sort(b+1,b+1+k);
	memset(dp,inf,sizeof(dp));
	for(int i=0;i<=k;i++)
	dp[0][i]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=k;j++)
		{
			dp[i][j]=min(dp[i][j-1],max(dp[i-1][j-1],abs(a[i]-b[j])+abs(p-b[j])));
		}

	}
	printf("%lld\n",dp[n][k]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=1e3+10;
int n,k;
ll a[maxn],p, b[maxn];
bool check(ll x)
{
	int item=1;
	for(int i=1;i<=n;i++)
	{
		while(item<=k&&abs(a[i]-b[item])+abs(b[item]-p)>x)
		item++;
		if(item>k)
		return false;
		item++;
	}
	return true;
}
int main(){

	scanf("%d %d %lld",&n,&k,&p);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	for(int i=1;i<=k;i++)
	scanf("%d",&b[i]);
	sort(a+1,a+1+n);
	sort(b+1,b+1+k);
	ll  l=0,r=LONG_LONG_MAX,mid;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(check(mid))
		{
			r=mid-1;
		}
		else
		l=mid+1;
	}
	printf("%lld\n",l);
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define uint unsigned int
#define LL long long
#define ULL unsigned LL
#define LD long double
#define VI vector<int>
#define X first
#define Y second
#define reads(_s) getline(cin,_s)
#define sz(_v) ((int)_v.size())
#define all(_v) (_v).begin(),(_v).end()
#define FOR(_i,a,b) for (int _i(a),_l(b); _i<=_l; ++_i)
#define rept(i,a) FOR(i,0,(int)(a)-1)
#define x1 X1
#define y1 Y1
#define sqr(a) ((a)*(a))
#define C(a) memset((a),0,sizeof (a))
#define MS(a,x) memset((a),(x),sizeof (a))
#define INF 1000000000
#define INFL INF*1ll*INF
#define eps 1e-6
#define MOD 1000000007
#define PRIME 312427
#define gets(s) getline(std::cin,s)

using namespace std;

int dist(int a, int k, int p) {
  return abs(a-k)+abs(k-p);
}

bool check(VI& people, VI keys, int p, int time) {
  rept(i,sz(people)) {
    int c_p(people[i]);
    while (dist(c_p,keys.back(),p) > time) {
      keys.pop_back();
      if (keys.empty()) return false;
    }
    keys.pop_back();
    if (keys.empty()) return false;
  }
  return true;
}

void solve() {
  int n,k,p;
  scanf("%d%d%d",&n,&k,&p);
  VI people(n),keys(k);
  rept(i,n) scanf("%d",&people[i]);
  rept(i,k) scanf("%d",&keys[i]);
  sort(all(people));
  sort(all(keys));
  reverse(all(keys));
  LL bad(0),good(2*1000*1000*1000);
  while (good-bad>1) {
    LL med((bad+good)/2);
    if (check(people,keys,p,med)) {
      good=med;
    } else {
      bad=med;
    }
  }
  if (check(people,keys,p,bad)) good=bad;
  printf("%d\n",good);
}

int main() {
#ifdef yeti
  freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout);
#endif

#ifdef yeti
  clock_t tm = clock();
  cout<<setprecision(10);
#endif
  solve();
#ifdef yeti
  cerr<<setprecision(3)<<(clock()-tm+0.)/CLOCKS_PER_SEC<<endl;
#endif
  return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define uint unsigned int
#define LL long long
#define ULL unsigned LL
#define LD long double
#define VI vector<int>
#define X first
#define Y second
#define reads(_s) getline(cin,_s)
#define sz(_v) ((int)_v.size())
#define all(_v) (_v).begin(),(_v).end()
#define FOR(_i,a,b) for (int _i(a),_l(b); _i<=_l; ++_i)
#define rept(i,a) FOR(i,0,(int)(a)-1)
#define x1 X1
#define y1 Y1
#define sqr(a) ((a)*(a))
#define C(a) memset((a),0,sizeof (a))
#define MS(a,x) memset((a),(x),sizeof (a))
#define INF 1000000000
#define INFL INF*1ll*INF
#define eps 1e-6
#define MOD 1000000007
#define PRIME 312427
#define gets(s) getline(std::cin,s)

using namespace std;

int dist(int a, int k, int p) {
  return abs(a-k)+abs(k-p);
}

bool check(VI& people, VI keys, int p, int time) {
  rept(i,sz(people)) {
    int c_p(people[i]);
    if (keys.empty()) return false;
    while (dist(c_p,keys.back(),p) > time) {
      keys.pop_back();
      if (keys.empty()) return false;
    }
    keys.pop_back();
  }
  return true;
}

void solve() {
  int n,k,p;
  scanf("%d%d%d",&n,&k,&p);
  VI people(n),keys(k);
  rept(i,n) scanf("%d",&people[i]);
  rept(i,k) scanf("%d",&keys[i]);
  sort(all(people));
  sort(all(keys));
  reverse(all(keys));
  LL bad(0),good(2*1000*1000*1000);
  while (good-bad>1) {
    LL med((bad+good)/2);
    if (check(people,keys,p,med)) {
      good=med;
    } else {
      bad=med;
    }
  }
  if (check(people,keys,p,bad)) good=bad;
  printf("%d\n",good);
}

int main() {
#ifdef yeti
  freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout);
#endif

#ifdef yeti
  clock_t tm = clock();
  cout<<setprecision(10);
#endif
  solve();
#ifdef yeti
  cerr<<setprecision(3)<<(clock()-tm+0.)/CLOCKS_PER_SEC<<endl;
#endif
  return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define uint unsigned int
#define LL long long
#define ULL unsigned LL
#define LD long double
#define VI vector<int>
#define X first
#define Y second
#define reads(_s) getline(cin,_s)
#define sz(_v) ((int)_v.size())
#define all(_v) (_v).begin(),(_v).end()
#define FOR(_i,a,b) for (int _i(a),_l(b); _i<=_l; ++_i)
#define rept(i,a) FOR(i,0,(int)(a)-1)
#define x1 X1
#define y1 Y1
#define sqr(a) ((a)*(a))
#define C(a) memset((a),0,sizeof (a))
#define MS(a,x) memset((a),(x),sizeof (a))
#define INF 1000000000
#define INFL INF*1ll*INF
#define eps 1e-6
#define MOD 1000000007
#define PRIME 312427
#define gets(s) getline(std::cin,s)

using namespace std;

int dist(int a, int k, int p) {
  return abs(a-k)+abs(k-p);
}

bool check(VI& people, VI keys, int p, int time) {
  rept(i,sz(people)) {
    int c_p(people[i]);
    while (dist(c_p,keys.back(),p) > time) {
      keys.pop_back();
      if (keys.empty()) return false;
    }
    keys.pop_back();
  }
  return true;
}

void solve() {
  int n,k,p;
  scanf("%d%d%d",&n,&k,&p);
  VI people(n),keys(k);
  rept(i,n) scanf("%d",&people[i]);
  rept(i,k) scanf("%d",&keys[i]);
  sort(all(people));
  sort(all(keys));
  reverse(all(keys));
  LL bad(0),good(2*1000*1000*1000);
  while (good-bad>1) {
    LL med((bad+good)/2);
    if (check(people,keys,p,med)) {
      good=med;
    } else {
      bad=med;
    }
  }
  if (check(people,keys,p,bad)) good=bad;
  printf("%d\n",good);
}

int main() {
#ifdef yeti
  freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout);
#endif

#ifdef yeti
  clock_t tm = clock();
  cout<<setprecision(10);
#endif
  solve();
#ifdef yeti
  cerr<<setprecision(3)<<(clock()-tm+0.)/CLOCKS_PER_SEC<<endl;
#endif
  return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define uint unsigned int
#define LL long long
#define ULL unsigned LL
#define LD long double
#define VI vector<int>
#define X first
#define Y second
#define reads(_s) getline(cin,_s)
#define sz(_v) ((int)_v.size())
#define all(_v) (_v).begin(),(_v).end()
#define FOR(_i,a,b) for (int _i(a),_l(b); _i<=_l; ++_i)
#define rept(i,a) FOR(i,0,(int)(a)-1)
#define x1 X1
#define y1 Y1
#define sqr(a) ((a)*(a))
#define C(a) memset((a),0,sizeof (a))
#define MS(a,x) memset((a),(x),sizeof (a))
#define INF 1000000000
#define INFL INF*1ll*INF
#define eps 1e-6
#define MOD 1000000007
#define PRIME 312427
#define gets(s) getline(std::cin,s)

using namespace std;

int dist(int a, int k, int p) {
  return abs(a-k)+abs(k-p);
}

bool check(VI& people, VI keys, int p, int time) {
  rept(i,sz(people)) {
    int c_p(people[i]);
    while (dist(c_p,keys.back(),p) > time) {
      keys.pop_back();
      if (keys.empty()) return false;
    }
    keys.pop_back();
  }
  return true;
}

void solve() {
  int n,k,p;
  scanf("%d%d%d",&n,&k,&p);
  VI people(n),keys(k);
  rept(i,n) scanf("%d",&people[i]);
  rept(i,k) scanf("%d",&keys[i]);
  sort(all(people));
  sort(all(keys));
  reverse(all(keys));
  int bad(0),good(2*1000*1000*1000);
  while (good-bad>1) {
    int med((bad+good)/2);
    if (check(people,keys,p,med)) {
      good=med;
    } else {
      bad=med;
    }
  }
  if (check(people,keys,p,bad)) good=bad;
  printf("%d\n",good);
}

int main() {
#ifdef yeti
  freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout);
#endif

#ifdef yeti
  clock_t tm = clock();
  cout<<setprecision(10);
#endif
  solve();
#ifdef yeti
  cerr<<setprecision(3)<<(clock()-tm+0.)/CLOCKS_PER_SEC<<endl;
#endif
  return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long

int n,k;

int a[1000000+5], b[1000000+5];

int mt[1000000+5];

bool used[1000000+5];

bool used1[1000000+5];

vector<vector<pair<int, int> > > d;

bool try_kuhn(int v, int l)
{
    if (used[v]) return false;
    used[v]=true;
    for (int i=0; i<d[v].size(); i++)
    {
        if (d[v][i].second>l) continue;
        int to=d[v][i].first;
        if (mt[to]==-1 || try_kuhn(mt[to],l))
        {
            mt[to]=v;
            return true;
        }
    }
}

bool check(int l)
{
    for (int i=0; i<k; i++)
    {
        mt[i]=-1;
    }
    for (int i=0; i<n; i++)
    {
        used1[i]=false;
    }
    for (int i=0; i<n; i++)
    {
        for (auto j:d[i])
        {
            if (j.second>l) continue;
            if (mt[j.first]==-1)
            {
                mt[j.first]=i;
                used1[i]=true;
                break;
            }
        }
    }
    for (int i=0; i<n; i++)
    {
        if (used1[i]) continue;
        for (int j=0; j<n; j++)
        {
            used[j]=false;
        }
        try_kuhn(i,l);
    }
    int cnt=0;
    for (int i=0; i<k; i++)
    {
        if (mt[i]!=-1) cnt++;
    }
    return cnt==n;
}

int binsearch(int l, int r)
{
    if (l==r) return l;
    if (l+1==r)
    {
        if (check(l)) return l;
        else return r;
    }
    int m=(l+r)/2;
    if (check(m)) return binsearch(l,m);
    else return binsearch(m,r);
}

main()
{
    int p;
    cin>>n>>k>>p;
    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for (int i=0; i<k; i++)
    {
        cin>>b[i];
    }
    d.resize(n);
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<k; j++)
        {
            int dst=abs(b[j]-a[i])+abs(b[j]-p);
            d[i].push_back({j,dst});
            //cout<<i<<" "<<j<<" "<<dst<<endl;
        }
    }
    int ans=binsearch(1,1000000000000000000LL);
    cout<<ans;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int n,k;

int a[1000000+5], b[1000000+5];

int mt[1000000+5];

bool used[1000000+5];

bool used1[1000000+5];

vector<vector<pair<int, int> > > d;

bool try_kuhn(int v, int l)
{
    if (used[v]) return false;
    used[v]=true;
    for (int i=0; i<d[v].size(); i++)
    {
        if (d[v][i].second>l) continue;
        int to=d[v][i].first;
        if (mt[to]==-1 || try_kuhn(mt[to],l))
        {
            mt[to]=v;
            return true;
        }
    }
}

bool check(int l)
{
    for (int i=0; i<k; i++)
    {
        mt[i]=-1;
    }
    for (int i=0; i<n; i++)
    {
        used1[i]=false;
    }
    for (int i=0; i<n; i++)
    {
        for (auto j:d[i])
        {
            if (j.second>l) continue;
            if (mt[j.first]==-1)
            {
                mt[j.first]=i;
                used1[i]=true;
                break;
            }
        }
    }
    for (int i=0; i<n; i++)
    {
        if (used1[i]) continue;
        for (int j=0; j<n; j++)
        {
            used[j]=false;
        }
        try_kuhn(i,l);
    }
    int cnt=0;
    for (int i=0; i<k; i++)
    {
        if (mt[i]!=-1) cnt++;
    }
    return cnt==n;
}

int binsearch(int l, int r)
{
    if (l==r) return l;
    if (l+1==r)
    {
        if (check(l)) return l;
        else return r;
    }
    int m=(l+r)/2;
    if (check(m)) return binsearch(l,m);
    else return binsearch(m,r);
}

int main()
{
    int p;
    cin>>n>>k>>p;
    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for (int i=0; i<k; i++)
    {
        cin>>b[i];
    }
    d.resize(n);
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<k; j++)
        {
            int dst=abs(b[j]-a[i])+abs(b[j]-p);
            d[i].push_back({j,dst});
            //cout<<i<<" "<<j<<" "<<dst<<endl;
        }
    }
    int ans=binsearch(1,1000000000);
    cout<<ans;
}