Language: C++

#include <algorithm>//min/max/sort(rand-access it)/merge
#include <array>
#include <bitset>
#include <climits>//INT_MAX/INT_MIN/ULLONG_MAX
#include <cmath>//fmin/fmax/fabs/sin(h)/cos(h)/tan(h)/exp/log/pow/sqrt/cbrt/ceil/floor/round/trunc
#include <cstdlib>//abs/atof/atoi/atol/atoll/strtod/strtof/..., srand/rand, calloc/malloc, exit, qsort
#include <iomanip>//setfill/setw
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <iterator>
#include <list>
#include <queue>
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline
#include <tuple>
#include <utility>//pair
#include <valarray>
#include <vector>

#define PRIME_SHORT 10007
#define PRIME 1000000007

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<ull, int> puli;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pllll;
typedef pair<ull, ull> pulul;
typedef pair<double, double> pdd;
typedef tuple<int, int, int> ti3;
typedef tuple<int, int, int, int> ti4;

const bool debug = false;

void rar(int n, int* a);
void rar2(int n, int m, int** a);

int ipow(int base, int exp);
int left(int current, bool swap);
int right(int current, bool swap);
int griddist(int x, int y, int s, int t);
int griddist(pii one, pii two);
double sqeucldist(double x, double y, double s, double t);
double sqeucldist(pii one, pii two);
ull modadd(ull a, ull b, int mod);
ull modmult(ull a, ull b, int mod);

bool check(ull* vals, int length)
{
    for (int i = 0; i < length; ++i)
    {
        if (vals[i] != 0)
        {
            return false;
        }
    }
    return true;
}
int main(void) {
    int n;
    cin >> n;
    ull* a = new ull[n];
    ull* b = new ull[n];
    rar(n, a);
    rar(n, b);
    ull* diff = new ull[n];
    for (int i = 0; i < n; ++i)
        diff[i] = a[i] - b[i];
    if (debug) {
        for (int i = 0; i < n; ++i)
            cout << diff[i] << '\t';
        cout << endl;
    }
    ull moves = 0UL;

    if (diff[0] > 0 && diff[1] < 0)
    {
        ull handoff = min(diff[0], -diff[1]);
        diff[0] -= handoff;
        diff[1] += handoff;
        moves += handoff;
    }
    if (diff[0] < 0)
    {
        ull handoff = -diff[0];
        diff[0] += handoff;
        diff[1] -= handoff;
        moves += handoff;
    }
    if (diff[n-1] > 0 && diff[n-2] < 0)
    {
        ull handoff = min(diff[n-1], -diff[n-2]);
        diff[n-1] -= handoff;
        diff[n-2] += handoff;
        moves += handoff;
    }
    if (diff[n-1] < 0)
    {
        ull handoff = -diff[n-1];
        diff[n-1] += handoff;
        diff[n-2] -= handoff;
        moves += handoff;
    }
    while (check(diff, n) == false)
    {
        int len = 1;
        for (int i = len; i < n-len; ++i)
        {
            if (diff[i] > 0)
            {
                if (diff[i+len] < 0)
                {
                    ull handoff = min(diff[i], -diff[i+len]);
                    diff[i] -= handoff;
                    diff[i+len] += handoff;
                    moves += len*handoff;
                }
                if (diff[i-len] < 0)
                {
                    ull handoff = min(diff[i], -diff[i-len]);
                    diff[i] -= handoff;
                    diff[i-len] += handoff;
                    moves += len*handoff;
                }
            }
            else if (diff[i] < 0)
            {
                if (diff[i+len] > 0)
                {
                    ull handoff = min(-diff[i], diff[i+len]);
                    diff[i] += handoff;
                    diff[i+len] -= handoff;
                    moves += len*handoff;
                }
                if (diff[i-len] > 0)
                {
                    ull handoff = min(-diff[i], diff[i-len]);
                    diff[i] += handoff;
                    diff[i-len] -= handoff;
                    moves += len*handoff;
                }
            }
        }
    }

    cout << moves << endl;
    return 0;
}

void rar(int n, int* a)
{
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    return;
}

void rar2(int n, int m, int** a)
{
    for (int i = 0; i < n; ++i)
    {
        a[i] = new int[m];
        for (int j = 0; j < m; ++j)
        {
            cin >> a[i][j];
        }
    }
    return;
}



















int ipow(int base, int exp) {
    int result = 1;
    while (exp)
    {
        if (exp & 1)
            result *= base;
        exp >>= 1;
        base *= base;
    }

    return result;
}
int left(int current, bool swap = false) {
    if(swap){
        return right(current, false);
    } else {
        return 2*current + 1;
    }
}
int right(int current, bool swap = false) {
    if(swap){
        return left(current, false);
    } else {
        return 2*(current+1);
    }
}
int griddist(int x, int y, int s, int t) {
    return abs(x-s) + abs(y-t);
}
int griddist(pii one, pii two) {
    return abs(one.first - two.first) + abs(one.second - two.second);
}
double sqeucldist(double x, double y, double s, double t) {
    double a = x-s;
    double b = y-t;
    return a*a+b*b;
}
double sqeucldist(pii one, pii two) {
    double a = one.first - two.first;
    double b = one.second - two.second;
    return a*a+b*b;
}

ull modadd(ull a, ull b, int mod) {
    return (a%mod + b%mod)%mod;
}
ull modmult(ull a, ull b, int mod) {
    return ((a%mod)*(b%mod))%mod;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:67:12: error: cannot convert 'ull*' {aka 'long long unsigned int*'} to 'int*'
   67 |     rar(n, a);
      |            ^
      |            |
      |            ull* {aka long long unsigned int*}
a.cc:38:22: note:   initializing argument 2 of 'void rar(int, int*)'
   38 | void rar(int n, int* a);
      |                 ~~~~~^
a.cc:68:12: error: cannot convert 'ull*' {aka 'long long unsigned int*'} to 'int*'
   68 |     rar(n, b);
      |            ^
      |            |
      |            ull* {aka long long unsigned int*}
a.cc:38:22: note:   initializing argument 2 of 'void rar(int, int*)'
   38 | void rar(int n, int* a);
      |                 ~~~~~^