#include <bits/stdc++.h>
using namespace std;
const double eps = 0.000000000000001;
string convertstring(long long n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
int a[2][1026];
int main() {
  int n, k, p, i, j;
  scanf("%d%d%d", &n, &k, &p);
  ;
  for (i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    ;
    a[0][x]++;
  }
  int ind = 0;
  for (i = 1; i <= k; ++i) {
    int sum = 0;
    for (j = 0; j <= 1024; ++j) {
      int x = ((a[ind][j] + 1) / 2);
      if (sum & 1) {
        a[ind ^ 1][j ^ p] += a[ind][j] - x;
        a[ind ^ 1][j] += x;
      } else {
        a[ind ^ 1][j] += a[ind][j] - x;
        a[ind ^ 1][j ^ p] += x;
      }
      sum += a[ind][j];
    }
    ind ^= 1;
    memset(a[ind ^ 1], 0, sizeof(a[ind ^ 1]));
    ;
  }
  int mn = 1000000001, mx = 0;
  for (i = 0; i <= 1024; ++i) {
    if (a[ind][i]) {
      mn = min(i, mn);
      mx = i;
    }
  }
  cout << mx << " " << mn << endl;
  return 0;
}
