Though ZCC has many Fans, ZCC himself is a crazy Fan of a coder, called "Memset137".
 It was on Codefires(CF), an online competitive programming site, that ZCC knew Memset137, and immediately became his fan. 
But why? 
 Because Memset137 can solve all problem in rounds, without unsuccessful submissions; his estimation of time to solve certain problem is so accurate, that he can surely get an Accepted the second he has predicted. He soon became IGM, the best title of Codefires. Besides, he is famous for his coding speed and the achievement in the field of Data Structures. 
 After become IGM, Memset137 has a new goal: He wants his score in CF rounds to be as large as possible. 
 What is score? In Codefires, every problem has 2 attributes, let's call them Ki and Bi(Ki, Bi>0). if Memset137 solves the problem at Ti-th second, he gained Bi-Ki*Ti score. It's guaranteed Bi-Ki*Ti is always positive during the round time. 
 Now that Memset137 can solve every problem, in this problem, Bi is of no concern. Please write a program to calculate the minimal score he will lose.(that is, the sum of Ki*Ti). 

Input The first line contains an integer N(1≤N≤10^5), the number of problem in the round. 

 The second line contains N integers Ei(1≤Ei≤10^4), the time(second) to solve the i-th problem. 


 The last line contains N integers Ki(1≤Ki≤10^4), as was described.

Output One integer L, the minimal score he will lose. Sample Input

3
10 10 20
1 2 3

Sample Output

150

Hint

Memset137 takes the first 10 seconds to solve problem B, then solves problem C at the end of the 30th second. Memset137 gets AK at the end of the 40th second.

L = 10 * 2 + (10+20) * 3 + (10+20+10) * 1 = 150.

排序即可,只要保证比值小的在前就一定是最优的,具体可以通过假设来证明。

#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define ms(x,y) memset(x,y,sizeof(x))
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define per(i,j,k) for(int i=j;i>=k;i--)
#define loop(i,j,k) for (int i=j;i!=-1;i=k[i])
#define inone(x) scanf("%d",&x)
#define intwo(x,y) scanf("%d%d",&x,&y)
#define inthr(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define infou(x,y,z,p) scanf("%d%d%d%d",&x,&y,&z,&p)
#define lson x<<1,l,mid
#define rson x<<1|1,mid+1,r
#define mp(i,j) make_pair(i,j)
#define ft first
#define sd second
typedef long long LL;
typedef pair<int, int> pii;
const int low(int x) { return x&-x; }
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const double eps = 1e-10;
int a[N],b[N],c[N],n;

bool cmp(int x,int y)
{
return b[x]*a[y]>a[x]*b[y];
}

int main()
{
while (~inone(n))
{
rep(i,1,n) inone(a[i]);
rep(i,1,n) inone(b[i]);
rep(i,1,n) c[i]=i;
sort(c+1,c+n+1,cmp);
LL ans=0,t=0;
rep(i,1,n) ans+=(t+=a[c[i]])*b[c[i]];
cout<<ans<<endl;
}
return 0;
}