//region TEMPLATE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(X) begin((X)), end((X))
#define sz(X) (int)(X).size()
#define fi first
#define se second
#define fv(X) for(auto&_:(X))cin>>_
#define fv2(X) for(auto&__:(X))fv(__)
#define lboundi(X, n) (lower_bound(all(X), n) - begin(X))
#define uboundi(X, n) (upper_bound(all(X), n) - begin(X))
#define maxi(X) max_element(all(X)) - begin(X)
#define maxe(X) *max_element(all(X))
#define mini(X) min_element(all(X)) - begin(X)
#define mine(X) *min_element(all(X))
#define acc(X) accumulate(all(X), 0LL)
#ifdef LOCAL
template<size_t S>
string to_string(const bitset<S> &x) { return x.to_string(); }
string to_string(const string &x) { return '"' + x + '"'; }
string to_string(char x) { return string{'\'', x, '\''}; }
string to_string(bool x) { return x ? "true" : "false"; }
template<typename Head, typename Tail>
string to_string(const pair<Head, Tail> &x) { return "(" + to_string(x.first) + ", " + to_string(x.second) + ")"; }
template<class T>
string to_string(T x) {
    string ret = "[";
    for (const auto &i: x)
        ret += to_string(i) + ", ";
    if (sz(ret) > 1)
        ret = ret.substr(0, sz(ret) - 2);
    return ret += "]";
}
string to_string(const char *x) { return string(x); }
string to_string() { return ""; }
template<typename Head, typename... Tail>
string to_string(Head H, Tail... T) { return to_string(H) + ", " + to_string(T...); }
#define debug(...) sizeof( (char[]){#__VA_ARGS__} ) == 1 ? cerr << endl \
: cerr << "[" << #__VA_ARGS__ << "]: " << to_string(__VA_ARGS__) << endl
#define nr() cerr << endl
#else
#define debug(...) 1
#endif
// endregion
class FenwickTreeSum {
private:
   int sum(int i) {
       if (i <= 0) return 0;
       int ret = 0;
       while (i) {
           ret += tree[i];
           i -= i & -i;
       }
       return ret;
   }
public:
   int n;
   vi tree;
   FenwickTreeSum(int n) : n(n) {
       tree.resize(n + 1);
   }
   void update(int i, int diff) {
       i++;
       while (i <= n) {
           tree[i] += diff;
           i += i & -i;
       }
   }
   int query(int l, int r) { return sum(r + 1) - sum(l); }
};
void solve() {
    int n;
    cin >> n;
    vi a(n), b(n);
    fv(a);
    fv(b);
    if (acc(a) != acc(b)) {
        cout << -1;
        return;
    }
    if (a == b) {
        cout << 0;
        return;
    }

    // 8

    map<int, vi> pos_a, pos_b;
    for (int i = 0; i < n; i++) {
        a[i] += i;
        b[i] += i;
        pos_a[a[i]].pb(i);
        pos_b[b[i]].pb(i);
    }
    vi inversion_count(n);
    for (const auto &p: pos_a) {
        const vi &bv = pos_b[p.fi];
        if (sz(p.se) != sz(bv)) {
            cout << -1;
            return;
        }

        for (int i = 0; i < sz(p.se); i++) {
            inversion_count[bv[i]] = p.se[i];
        }
    }
    debug(inversion_count);
    FenwickTreeSum fenwick(n);
    ll ret = 0;
    for (int i = 0; i < n; i++) {
        ret += fenwick.query(inversion_count[i], n - 1);
        debug(fenwick.query(0, n - 1));
        fenwick.update(inversion_count[i], 1);
    }

    cout << ret;
}

int main() {
    fastio
    solve();
    return 0;
}
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")

#include "bits/stdc++.h"
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'
#define F first
#define S second
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define cf ll testcases;cin>>testcases;while(testcases--)
#define prn(x) if(x) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define minel(x) (*min_element(all(x)))
#define maxel(x) (*max_element(all(x)))
#define cou dbg=1;cout
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<ld> vd;
typedef vector<pi> vp;
ll dbg=0;
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p);
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p);
template<typename A> istream& operator>>(istream& cin, vector<A> &v);
int dx[] = {-1, -1, -1,  0, 0,  1, 1, 1};
int dy[] = {-1,  0,  1, -1, 1, -1, 0, 1};

void solve(){
    ll n;
    cin>>n;
    vi arr(n);
    cin>>arr;
    ll man=0;
    for(auto i:arr) man+=abs(i);
    cout<<man<<endl;
    ll euc=0;
    for(auto i:arr) euc+=i*i;
    cout.precision(15);
    cout<<fixed<<sqrt(euc)<<endl;
    ll cheb=LLONG_MIN;
    for(auto i:arr) cheb=max(cheb,abs(i));
    cout<<cheb<<endl;
    
}

int main(){
    IO;
    // cf
    solve();
    return 0;
}


template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { 
    if(dbg){
        return cout << "(" << p.F << ", " << p.S << ")"; 
    }else{
        return cout<<p.F<<' '<<p.S;
    }
        dbg=0;}
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
    if(dbg){
        cout << "["; for(ll i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
    }else{
        for(ll i=0;i<v.size()-1;i++) cout<<v[i]<<' ';
        return cout<<v[v.size()-1];
    dbg=0;}
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
   cin >> p.first;
   return cin >> p.second;
}
template<typename A> istream& operator>>(istream& cin, vector<A> &v) {
   for(ll i=0;i<v.size()-1;i++) cin>>v[i];
   return cin >> v[v.size()-1];
}