#include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef vector vi; typedef vector vvi; #define rep(i,n) for(ll i=0;i<(n);i++) #define pii pair #define piii pair #define mp make_pair #define pb push_back #define ALL(a) (a).begin(),(a).end() #define FST first #define SEC second const int INF = (INT_MAX/2); const ll LLINF = (LLONG_MAX/2); const double eps = 1e-5; const double PI = M_PI; #define DEB cerr<<"!"<> n; vi a(n),b(n); rep(i,n) cin >> a[i]; rep(i,n) cin >> b[i]; int ans = INF; rep(index,n){ priority_queue> q; rep(i,n) q.push(a[i] * 2000); int i = index; bool ii = 1; while(ii){ int s = q.top(); q.pop(); s += (b[i]/2)*2000 + 1; q.push(s); SHOW(index,i); i++; if(i == n) i=0; if(i==index) ii = 0; } int ta = 0; while(!q.empty()){ ta = max(ta,q.top() % 2000); q.pop(); } ans = min(ta,ans); } cout << ans << endl; return 0; }