#include <iostream>
#include <bits/stdc++.h>
using namespace std;

// sample input:-
// 4 
// 1 3 2 5 
// 3 5 3 6 
// 2 
// 1 3 
// 4 6 

// answer should be 7

int main() {
	// your code goes here
	
	int n;
	cin>> n;
	
	vector<int> st(n,0), end(n,0);
	
	// track max;
	int mx=0;
	
	for(int i=0; i<n; i++){
		cin>>st[i];
	}
	for(int i=0; i<n; i++){
		cin>>end[i];
		mx = max(mx, end[i]);
	}
	
	int k;
	cin>> k;
	int qs[2], qe[2];
	
	cin>>qs[0];
	cin>>qs[1];
	cin>>qe[0];
	cin>>qe[1];
	
	
	
	// <<<<<<<<<<<--------------------------->>>>>>>>>>>>
	// solution
	
	// 1 indexed prefix sum that's why (mx+1)
	vector<int> pre (mx+1, 0);
	
	
	// update pre with 1 or -1
	for(int i=0; i<n; i++){
		
		// from st
		pre[st[i]] += 1;
		
		// from end. only skip if it's the last element
		// because last +1 doesn't exist to put -1
		if(end[i]!=mx) pre[end[i]+1] += -1;
		
		
	}
	
	// calculate pre
	for(int i=1; i<=mx; i++){
		pre[i]+=pre[i-1];
	}
	
	int ans=0;
	
	// if(pre[i]>=k) ans+=pre[i];
	
	// find each hour which is in range of both the queries.
	// queries might be overlapping. so 
	vector<int> arr(mx+1, 0);
	
	for(int i=qs[0]; i<=qe[0]; i++){
		if(pre[i]>=k) arr[i]++;
	}
	for(int i=qs[1]; i<=qe[1]; i++){
		if(pre[i]>=k) arr[i]++;
	}
	
	
	
	// calculate for each one in the range of queries
	// and add that hour's pre value in ans
	for(int i=0; i<mx+1; i++){
		if(arr[i]!=0) ans+=pre[i];
	}
	
	
	// for(auto x: pre) cout<<x<<endl;
	cout<< ans;
	
	return 0;
}