#include <bits/stdc++.h>   using namespace std;   int Matrix[1002][2002];   int max(int a, int b) {     if (a > b)       return a;     else       return b;   }   int min(int a, int b) {     if (a < b)       return a;     else       return b;   }   int distance(int a, int b, int c) {     int first, second;     first = a < b ? b - a : a - b;     second = b < c ? c - b : b - c;     return first + second;   }   int main() {     int n, k, p;     int person[1005];     int key[2002];     cin >> n >> k >> p;     for (int i = 1; i <= n; i++) cin >> person[i];     for (int i = 1; i <= k; i++) cin >> key[i];     sort(person + 1, person + n + 1);     sort(key + 1, key + k + 1);     for (int i = 1; i <= n; i++) {       for (int j = i; j <= k; j++) {         if (i == j) {           Matrix[i][j] =               max(Matrix[i - 1][j - 1], distance(person[i], key[i], p));         } else {           Matrix[i][j] =               min(Matrix[i][j - 1],                   max(Matrix[i - 1][j - 1], distance(person[i], key[j], p)));         }       }     }     int ans = 2e9;     for (int i = n; i <= k; i++) ans = min(ans, Matrix[n][i]);     cout << ans << endl;   }   