#include using namespace std; typedef long long int ll; typedef pair P; typedef vector VI; typedef vector VVI; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template bool chmax(T &x, const T &y) {return (x bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;}; constexpr ll MOD=998244353; constexpr ll INF=2e18; int main() { int n; cin >> n; VI a(n), b(n); REP(i,n) cin >> a[i]; REP(i,n) cin >> b[i]; set s; int ans=0; REP(i,n){ int d=abs(a[i]-b[i]); ans+=d; s.insert(i); } cout << ans << endl; VI c(n,-1), f(n,0); while(ans){ for(auto i:s){ c[i]=-1; f[i]=0; } for(auto i:s){ if(i0&&a[i]>b[i]&&a[i-1]!=b[i-1]&&a[i]-1==a[i-1]){ c[i-1]=i; f[i]=1; } } set es; for(auto i:s){ if(!f[i]){ int now=i; while(now!=-1){ if(a[now]==b[now]) break; if(a[now]