#include "bits/stdc++.h"
#define sd(n) scanf("%d", &(n))
#define rep(i, x, n) for (size_t i = x, _n = (n); i < _n; ++i)
#define SZ(c) (int)(c).size()
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define VI vector<int>
#define all(c) ((c).begin(), (c).end())
#define pb push_back
#define pii pair<int, int>
#define pip pair<int, pii>
#define F first
#define S second
#define mp make_pair
#define lli long long int
#define CLR(p) memset(p, 0, sizeof(p))
#define SET(p) memset(p, -1, sizeof(p))
#define INF 0x3f3f3f3f
using namespace std;
const int MOD = 1e9+7;
const int MAX = 2001;
int dx[] = {0, -1, 1, 0};
int dy[] = {1, 0, 0, -1};
char mat[2004][2004];
int visited[2004][2004];
class TheGridDivTwo
{
public:
int dfs(int p, int q, int k)
{
visited[p][q] = 1;
if(k == 0)
{
return q;
}
int maxi = q; //changed INT_MIN to q
rep(j, 0, 4)
{
int x = p + dx[j];
int y = q + dy[j];
if(x < 0 || y < 0 || x >= MAX || y >= MAX)
continue;
if(mat[x][y] == '.' && !visited[x][y])
{
maxi = max(maxi, dfs(x, y, k-1));
}
}
return maxi;
}
int find(vector <int> x, vector <int> y, int k)
{
int n =x.size();
if(n == 0) return k;
rep(i, 0, MAX)
rep(j, 0, MAX)
mat[i][j] = '.';
rep(i, 0, n)
mat[1000+y[i]][1000+x[i]] = 'x';
int ans = max(1000, dfs(1000, 1000, k)); //added a max check
if(ans == 1000) return 0; //changed INT_MIN to 1000
return ans-1000;
}
};
int main()
{
TheGridDivTwo TG;
int n, k;
cin >> n;
VI x(n), y(n);
rep(i, 0, n)
cin >> x[i];
rep(i, 0, n)
cin >> y[i];
cin >> k;
cout << TG.find(x, y, k) << endl;
return 0;
}
I2luY2x1ZGUgImJpdHMvc3RkYysrLmgiCiNkZWZpbmUgc2Qobikgc2NhbmYoIiVkIiwgJihuKSkKI2RlZmluZSByZXAoaSwgeCwgbikgZm9yIChzaXplX3QgaSA9IHgsIF9uID0gKG4pOyBpIDwgX247ICsraSkKI2RlZmluZSB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