#include<iostream>#include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>#include<algorithm>#include<map>#include<vector>#include<queue>usingnamespace std;constint maxn =1e5+5;int coupon[maxn], value[maxn];int n, m;intmain(){#ifdef ONLINE_JUDGE#elsefreopen("1.txt","r",stdin);#endif// ONLINE_JUDGEscanf("%d",&n);for(int i =0; i < n; i++)scanf("%d",&coupon[i]);sort(coupon, coupon+n, greater<int>());scanf("%d",&m);for(int i =0; i < m; i++)scanf("%d",&value[i]);sort(value, value+m, greater<int>());int cnt =0;int i, j;for(i =0; i < n && i < m; i++){if(coupon[i]*value[i]>0) cnt += coupon[i]*value[i];elsebreak;}if(i>=n || i>=m){printf("%d\n", cnt);return0;}
i = n-1;
j = m-1;for(; i>=0&&j>=0;){if(coupon[i]*value[j]>0){
cnt += coupon[i]*value[j];
i--, j--;}elsebreak;}printf("%d\n", cnt);return0;}