#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
const char E = '\n';
const int N = 1005;
const ll mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k, x, dp[2][1024] = {0};
  cin >> n >> k >> x;
  for (int i = 1; i <= n; i++) {
    int y;
    cin >> y;
    dp[1][y]++;
  }
  for (int i = 1; i <= k; i++) {
    int used = 0;
    for (int j = 0; j <= 1023; j++) {
      int bit, nbit;
      bit = i & 1, nbit = i & 1 ^ 1;
      if (!(dp[bit][j] & 1)) {
        dp[nbit][j] += (dp[bit][j] >> 1);
        dp[nbit][j ^ x] += (dp[bit][j] >> 1);
      } else if (dp[bit][j]) {
        dp[nbit][j] += (dp[bit][j] >> 1) + (used & 1);
        dp[nbit][j ^ x] += (dp[bit][j] >> 1) + (used & 1 ^ 1);
      }
      used += dp[bit][j];
      dp[bit][j] = 0;
    }
  }
  int mx = 0, mn = 1024;
  for (int i = 0; i <= 1023; i++) {
    if (dp[k & 1 ^ 1][i]) {
      mx = max(mx, i);
      mn = min(mn, i);
    }
  }
  cout << mx << " " << mn << E;
  return 0;
}
