import java.io.*;
import java.util.Arrays;
public class Main {
static int N=100010;
static int[] a=new int[N];
static long[] s=new long[N];
//差分数组
static long[] g=new long[N];
static int n;
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
n=Integer.parseInt(br.readLine());
String[] v=br.readLine().split(" ");
for (int i = 1; i <=n; i++) {
a[i]=Integer.parseInt(v[i-1]);
s[i]=s[i-1]+a[i];
}
int m=Integer.parseInt(br.readLine());
long res=0;
for (int i = 0; i < m; i++) {
v=br.readLine().split(" ");
int l=Integer.parseInt(v[0]);
int r=Integer.parseInt(v[1]);
g[l]++;
g[r+1]--;
res+=s[r]-s[l-1];
}
for (int i = 1; i <=n; i++) {
g[i]+=g[i-1];
}
long ans=0;
Arrays.sort(a);
Arrays.sort(g);
int pre=g.length-1;
while (g[pre]!=0){
ans+=g[pre] *a[pre];
pre--;
}
System.out.println(ans-res);
}
}