#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <functional>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <bitset>
#include <cassert>
#include <math.h>
#include <complex>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#ifdef _OLIMPOLOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 1337
#endif
void debug_out() { cout << "\n";}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " " << A; debug_out(B...); }
int test = 1;
#define out(x) {cout << x << "\n";return;}
#define all(N) N.begin(),N.end()
#define allr(N) N.rbegin(),N.rend()
template<typename T1> 
void print(vector<T1> V, int add = 0, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = V.size() - 1;
    for (int i = start; i <= end; i++) {
        cout << V[i] + add << ((i == end) ? "\n" : " ");
    }
}
template<typename T1> 
T1 chmin(T1 &x, const T1 v) { return x = min(x,v); }
template<typename T1> 
T1 chmax(T1 &x, const T1 v) { return x = max(x,v); }
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repsr(i, s, n) for (int i = n-1; i >= s; i--)
#define PI pair<int,int>
//-------------------------- ^ DONT TOUCH ^-----------------------------------------------------------------
#define MAX 100001
#define MOD 1000000007ll

vector<int> G[MAX];

bool cmp(const pair<int, int> a,const pair<int, int> b) {
    return a.first - a.second < b.first - b.second;
}

pair<int, int> dfs(int n) {
    pair<int, int> r = {1,0};
    pair<int, int> pp = {0,0};
    vector<pair<int, int>> P;
    for(auto &g : G[n]) {
        auto p = dfs(g);
        if ((p.first + p.second) % 2 == 0) {
            if (p.second > p.first) {
                r.first +=p.first;
                r.second += p.second;
            } else {
                pp.first +=p.first;
                pp.second += p.second;
            }
        } else
        {
            P.push_back(p);
        }        
    }
    if (P.size() % 2 == 0) {
        r.first +=pp.first;
        r.second += pp.second;
    } else {
        r.first +=pp.second;
        r.second += pp.first;
    }

    sort(P.begin(), P.end(), cmp);
    for(int i = 0; i < P.size(); i++) {
        if (i % 2 == 0) {
            r.first +=P[i].first;
            r.second += P[i].second;
        } else {
            r.first += P[i].second;
            r.second += P[i].first;
        }
    }
    return r;
}

void solve() {
    int n, x;
    cin >> n;
    rep(i,n) G[i].clear();
    reps(i, 1, n) {
        cin >> x;
        G[x-1].push_back(i);
    }
    auto p = dfs(0);
    out(p.first);
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int test = 1;
    //cin >> test;
    rep(testCase, test) {
        #ifdef _OLIMPOLOCAL
            cout << "------------------ TESTCASE: " << testCase << " -------------\n";
        #endif
        solve();
    }
    return 0;
}
//Code Written by Pinaki Bhattacharjee
#include<bits/stdc++.h>
using namespace std;

// typedef
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

// #define
#define LOCAL
#define INF 1e18
#define MAX 10000
#define PI 2*acos(0.0)
#define endl "\n"
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define set_bits __builtin_popcountll
#define DEBUG(x) cerr << #x << " = " << x << endl;
#define pinakipb2 ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

// constants
const int MOD = (int) 1e9 + 7;

// debugger
#ifdef LOCAL
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
    #define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " | ";
    __f(comma + 1, args...);
}

/*--------------------------------------------------------------------------------------------------------------------------*/

#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x<<" "; _print(x); cerr << endl;
#else
    #define debug(x);
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(ld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

void google(int t) {cout << "Case #" << t << ": ";}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

/*--------------------------------------------------------------------------------------------------------------------------*/

int main()
{
    pinakipb2;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("error.txt","w",stderr);
    #endif
    // Code begins
    
    ll n;
    cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    ll ans = 0;
    ll a = 0, b = 0;
    for(int i=0;i<n;i++)
    {
        a+=arr[i]*arr[i];
        b+=arr[i];
    }
    ans = (n*a)-(b*b);
    cout<<ans<<endl;
    
    // Code ends
    return 0;
}