#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a (n);
vector<int> b (n);
for (auto& x: a) cin >> x;
for (auto& x: b) cin >> x;
vector<int> delta (n);
for (int i = 0; i < n; i++) delta[i] = b[i] - a[i];
vector<int> flow (n);
flow[0] = 0;
for (int i = 1; i < n; i++) flow[i] = flow[i - 1] + delta[i - 1];
sort(flow.begin(), flow.end());
int rem = flow[n / 2];
int ans = 0;
for (auto& x: flow) ans += abs(x - rem);
cout << ans << '\n';
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgaW50IGxvbmcgbG9uZwp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc2lnbmVkIG1haW4oKSB7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKG51bGxwdHIpOwogICAgCiAgICBpbnQgbjsKICAgIGNpbiA+PiBuOwogICAgdmVjdG9yPGludD4gYSAobik7CiAgICB2ZWN0b3I8aW50PiBiIChuKTsKICAgIGZvciAoYXV0byYgeDogYSkgY2luID4+IHg7CiAgICBmb3IgKGF1dG8mIHg6IGIpIGNpbiA+PiB4OwoKICAgIHZlY3RvcjxpbnQ+IGRlbHRhIChuKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSBkZWx0YVtpXSA9IGJbaV0gLSBhW2ldOwogICAgdmVjdG9yPGludD4gZmxvdyAobik7CiAgICBmbG93WzBdID0gMDsKICAgIGZvciAoaW50IGkgPSAxOyBpIDwgbjsgaSsrKSBmbG93W2ldID0gZmxvd1tpIC0gMV0gKyBkZWx0YVtpIC0gMV07CiAgICBzb3J0KGZsb3cuYmVnaW4oKSwgZmxvdy5lbmQoKSk7CiAgICBpbnQgcmVtID0gZmxvd1tuIC8gMl07CiAgICBpbnQgYW5zID0gMDsKICAgIGZvciAoYXV0byYgeDogZmxvdykgYW5zICs9IGFicyh4IC0gcmVtKTsKICAgIGNvdXQgPDwgYW5zIDw8ICdcbic7Cn0=