#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=100010;
int T,n,q,l,r;
int a[N],b[N];
int ans;
int k;
int maxx1,maxx2;
signed main(){
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	cin>>T>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	for(int i=1;i<=n;++i){
		cin>>b[i];
	}
	cin>>q;
	while(q--){
		cin>>l>>r;
		k=r-l+1;
		for(int i=l;i<=r;++i)ans+=a[i]*b[i];
		sort(a+n,a+n+1);
		sort(b+n,b+n+1);
		for(int i=l;i<=r;++i) ans+=a[i]*b[i];
	}
	cout<<ans;
	return 0;
}