#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct SegTree {
vector<pair<int, int>> tree;
int N;
void init(int x) {
N = x;
tree = vector<pair<int, int>>(N * 4 + 1);
}
void build(vector<pair<int, int>> &v) {
build(1, 1, N, v);
}
void build(int node, int s, int e, vector<pair<int, int>> &v) {
if (s == e) {
tree[node] = {v[s].first, s};
return;
}
int mid = (s + e) / 2;
build(node * 2, s, mid, v);
build(node * 2 + 1, mid + 1, e, v);
tree[node] = min(tree[node * 2], tree[node * 2 + 1]);
}
int query(int l, int r) {
return query(1, 1, N, l, r).second;
}
pair<int, int> query(int node, int s, int e, int l, int r) {
if (e < l || r < s)
return {1e9, 0};
if (l <= s && e <= r)
return tree[node];
int mid = (s + e) / 2;
return min(query(node * 2, s, mid, l, r), query(node * 2 + 1, mid + 1, e, l, r));
}
} seg_tree;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<pair<int, int>> A(N / 2 + 1);
for (int i = 1, x1, y1, x2, y2; i <= N / 2; i++) {
cin >> x1 >> y1 >> x2 >> y2;
A[i] = {y2, x1};
}
seg_tree.init(N / 2);
seg_tree.build(A);
priority_queue<ll> pq;
auto f = [&](auto&& self, int s, int e, int v) -> ll {
if (s > e)
return 0;
int idx = seg_tree.query(s, e);
ll c1 = self(self, s, idx - 1, A[idx].first);
ll c2 = self(self, idx + 1, e, A[idx].first);
pq.push(min(c1, c2));
assert(pq.size() <= 5000000);
return max(c1, c2) + 1LL * (A[idx].first - v) * (A[e + 1].second - A[s].second);
};
pq.emplace(f(f, 1, N / 2 - 1, 0));
int K;
cin >> K;
ll ans = 0;
while (!pq.empty() && K--) {
ans += pq.top();
pq.pop();
}
cout << ans << "\n";
}