// #ifdef ONLINE_JUDGE
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #endif
#include "bits/stdc++.h"
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define FOR(i, a, b) for(__typeof(b) i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for(__typeof(a) i = a, _b = b; i >= _b; --i)
#define ALL(a) (a).begin(), (a).end()
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ii pair<int,int>
#define iii pair<int,pair<int,int>>
#define dq deque<int>
#define nend '\n'
using namespace std;
const ll inf = 1e18;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
const int MOD = 1e9 + 7;
const ll hashi = 2e9 + 11;
void init_code() {
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const int K = 1500;
ll f[K+1];
void solve() {
int n;
cin >> n;
vector<ll> m(n), p(n);
for (auto& x : m) cin >> x;
for (auto& x : p) cin >> x;
FOR(i,0,K) f[i]=-inf;
f[0] = 0;
for (int i = n-1; i>=0; i--) {
int lim = min(K, n-i);
for (int c = lim; c >= 1; c--) // backwards so f[c-1] is still the old value
if (f[c-1] != -inf)
f[c] = max(f[c], f[c-1] + p[i] - c * m[i]);
}
cout << *max_element(f,f+K+1);
}
int main() {
init_code();
int t=1;
// cin >> t;
while (t--) {
solve();
}
}