#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
vector<int>to[100005];
int dp[100005];
int sz[100005];

void dfs(int v, int p = -1) {
	int csub = 0;
	dp[v] = 1;
	sz[v] = 1;
	vector<int>c;
	for (int e : to[v]) {
		if (p == e) {
			continue;
		}
		dfs(e, v);
		sz[v] += sz[e];
		int num = dp[e];
		if ((num < 0) && (0 == (sz[e] % 2))) {
			//case1
			dp[v] += num;
		}
		else if ((num >= 0) && (0 == (sz[e] % 2))) {
			//case2
			csub += num;
		}
		else {
			//case3
			c.push_back(num);
		}
	}
	sort(all(c));
	c.push_back(csub);
	rep(i, c.size()) {
		if (0 == i % 2) {
			dp[v] += c[i];
		}
		else {
			dp[v] -= c[i];
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	rep(i, N - 1) {
		int p;
		cin >> p;
		p--;
		to[i + 1].push_back(p);
		to[p].push_back(i + 1);
	}
	dfs(0);
	int ans = (dp[0] + N) / 2;
	cout << ans << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

// For Policy Based DS
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// ---------------------------------------
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              emplace_back
#define mp              make_pair
#define pll             pair<int,int>
#define vll             vector<int>
#define vpll            vector<pair<int,int>>
#define all(c)          (c).begin(), (c).end()
#define bs              binary_search
#define pqb             priority_queue<int>
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define mem(arr,x)      memset(arr,x,sizeof(arr))
#define pi              3.14159265358979323846
#define inf             2000000000000000000
#define ps(x,y)         fixed<<setprecision(y)<<x
#define test(x)         int x; cin>>x;while(x--)

template<class A> void read(vector<A>& v);
template<class A, size_t S> void read(array<A, S>& a);
template<class T> void read(T& x) {
  cin >> x;
}
void read(double& d) {
  string t;
  read(t);
  d = stod(t);
}
void read(long double& d) {
  string t;
  read(t);
  d = stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
  read(h);
  read(t...);
}
template<class A> void read(vector<A>& x) {
  for (auto &a : x)
    read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
  for (auto &a : x)
    read(a);
}

const int d4i[4] = { -1, 0, 1, 0};
const int d4j[4] = {0, 1, 0, -1};
const int d8i[8] = { -1, -1, 0, 1, 1, 1, 0, -1};
const int d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};
void c_p_c()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input", "r", stdin);
  freopen("output", "w", stdout);
#endif
}
string int_to_string(int n) {
  ostringstream str1;
  str1 << n;
  string sar = str1.str();
  return sar;
}
int pow(int a, int b, int m)
{
  int res = 1;
  while (b > 0)
  {
    if (b % 2)
      res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
int ncr(int  n, int k)
{ if (k == 0)
    return 1;
  if (k > n - k)
    k = n - k;
  int a = 1, b = 1, d;
  while (k)
  { a *= n; b *= k;
    d = __gcd(a, b);
    a /= d; b /= d;
    n--; k--;
  }
  return a;
}
int modinv(int k, int m)
{
  return pow(k, m - 2, m);
}
/***************************CODE BEGINS**************************************/
void solve ()
{
  int n;
  read(n);
  int A[n+2];
  for(int i=1;i<=n;i++)
    cin>>A[i];
  int ans=-inf;
  for(int i=1;i<=n;i++){
    int t=inf;
     for(int j=i;j<=n;j++){
        t=min(t,A[j]);
        int k=t*(j-i+1);
        ans=max(ans,k);
     }
  }
  cout<<ans;
}
int32_t main()
{
  c_p_c();
  // test(x)
  solve();
  // int count=1;
  // test(x){
  //   cout<<"Case #"<<count<<": ";
  //   count++;
  //   solve();
  // }
  return 0;
}