stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back

#define pi (acos(-1))

#define ull  unsigned long long

#define ld long double

///freopen("input.txt","r",stdin);

///freopen("output.txt","w",stdout);

#define M 100000

ll LCM(ll a, ll b)

{

    ll g = __gcd(a,b);

    return (a*b)/g ;

}

string numtostr(ll n)

{

    ostringstream str1 ;

    str1 << n ;

    return str1.str();

}

ll strtonum(string s)

{

    ll x ;

    stringstream str1(s);

    str1 >> x ;

    return x ;

}

int h1,m1,h2,m2,a;

int main(void)

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    cin>>h1>>m1>>h2>>m2>>a;

    cout<<h2*60+m2-(h1*60+m1)-a<<'\n';

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.4287453118217455x):
#include<stdio.h>

int main(){

	int h1,h2,m1,m2,k;

	int a,b,c,d;

	

	scanf("%d %d %d %d %d", &h1,&m1,&h2,&m2,&k);

	

	a = (h1*60) +m1;

	b=(h2*60) +m2;

	c = b-a;

	d = c- k;  

	

	printf("%d\n", d);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	int h1, m1, h2, m2; cin >> h1 >> m1 >> h2 >> m2;

	int k; cin >> k;

	cout << (h2 * 60 + m2 - h1 * 60 - m1 - k) << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.309312860838125x):
#include<stdio.h>

int main(){

	int h1,h2,m1,m2,k;

	int a,b,c,d;

	

	scanf("%d %d %d %d %d", &h1,&m1,&h2,&m2,&k);

	

	a = (h1*60) +m1;

	b=(h2*60) +m2;

	c = b-a;

	d = c- k;  

	

	printf("%d\n", d);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back

#define pi (acos(-1))

#define ull  unsigned long long

#define ld long double

///freopen("input.txt","r",stdin);

///freopen("output.txt","w",stdout);

#define M 100000

ll LCM(ll a, ll b)

{

    ll g = __gcd(a,b);

    return (a*b)/g ;

}

string numtostr(ll n)

{

    ostringstream str1 ;

    str1 << n ;

    return str1.str();

}

ll strtonum(string s)

{

    ll x ;

    stringstream str1(s);

    str1 >> x ;

    return x ;

}

int h1,m1,h2,m2,a;

int main(void)

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    cin>>h1>>m1>>h2>>m2>>a;

    cout<<h2*60+m2-(h1*60+m1)-a<<'\n';

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.442463566295968x):
#include<stdio.h>

int main()

{

	int H1,M1,H2,M2,K;

	scanf("%d %d %d %d %d",&H1,&M1,&H2,&M2,&K);

	M1 += H1 * 60;

	M2 += H2 * 60;

	int df = M2 - M1;

	printf("%d", df - K);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	int h1, m1, h2, m2; cin >> h1 >> m1 >> h2 >> m2;

	int k; cin >> k;

	cout << (h2 * 60 + m2 - h1 * 60 - m1 - k) << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.322729313577146x):
#include<stdio.h>

int main()

{

	int H1,M1,H2,M2,K;

	scanf("%d %d %d %d %d",&H1,&M1,&H2,&M2,&K);

	M1 += H1 * 60;

	M2 += H2 * 60;

	int df = M2 - M1;

	printf("%d", df - K);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back

#define pi (acos(-1))

#define ull  unsigned long long

#define ld long double

///freopen("input.txt","r",stdin);

///freopen("output.txt","w",stdout);

#define M 100000

ll LCM(ll a, ll b)

{

    ll g = __gcd(a,b);

    return (a*b)/g ;

}

string numtostr(ll n)

{

    ostringstream str1 ;

    str1 << n ;

    return str1.str();

}

ll strtonum(string s)

{

    ll x ;

    stringstream str1(s);

    str1 >> x ;

    return x ;

}

int h1,m1,h2,m2,a;

int main(void)

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    cin>>h1>>m1>>h2>>m2>>a;

    cout<<h2*60+m2-(h1*60+m1)-a<<'\n';

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.442331269496831x):
#include <stdio.h>

#include <string.h>



int main(){

	int H1, M1, H2, M2, K; 

	scanf ("%d %d %d %d %d", &H1, &M1, &H2, &M2, &K);

	int Tot1 = (H1*60)+M1;

	int Tot2 = (H2*60)+M2;

	int Time = (Tot2 - Tot1) - K;

	printf ("%d", Time); 







return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	int h1, m1, h2, m2; cin >> h1 >> m1 >> h2 >> m2;

	int k; cin >> k;

	cout << (h2 * 60 + m2 - h1 * 60 - m1 - k) << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.32259992730891x):
#include <stdio.h>

#include <string.h>



int main(){

	int H1, M1, H2, M2, K; 

	scanf ("%d %d %d %d %d", &H1, &M1, &H2, &M2, &K);

	int Tot1 = (H1*60)+M1;

	int Tot2 = (H2*60)+M2;

	int Time = (Tot2 - Tot1) - K;

	printf ("%d", Time); 







return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back

#define pi (acos(-1))

#define ull  unsigned long long

#define ld long double

///freopen("input.txt","r",stdin);

///freopen("output.txt","w",stdout);

#define M 100000

ll LCM(ll a, ll b)

{

    ll g = __gcd(a,b);

    return (a*b)/g ;

}

string numtostr(ll n)

{

    ostringstream str1 ;

    str1 << n ;

    return str1.str();

}

ll strtonum(string s)

{

    ll x ;

    stringstream str1(s);

    str1 >> x ;

    return x ;

}

int h1,m1,h2,m2,a;

int main(void)

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    cin>>h1>>m1>>h2>>m2>>a;

    cout<<h2*60+m2-(h1*60+m1)-a<<'\n';

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.4426213847823774x):
#include <stdio.h>

#include <string.h>

#define ll long long int



int main(){

int h1,m1,h2,m2,d;

scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&d);

int hminutes = (h2-h1) * 60;

int mminutes = m2-m1;

int tminutes = hminutes + mminutes;

int res = tminutes - d;

printf("%d",res);

return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	int h1, m1, h2, m2; cin >> h1 >> m1 >> h2 >> m2;

	int k; cin >> k;

	cout << (h2 * 60 + m2 - h1 * 60 - m1 - k) << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.322883660055281x):
#include <stdio.h>

#include <string.h>

#define ll long long int



int main(){

int h1,m1,h2,m2,d;

scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&d);

int hminutes = (h2-h1) * 60;

int mminutes = m2-m1;

int tminutes = hminutes + mminutes;

int res = tminutes - d;

printf("%d",res);

return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back

#define pi (acos(-1))

#define ull  unsigned long long

#define ld long double

///freopen("input.txt","r",stdin);

///freopen("output.txt","w",stdout);

#define M 100000

ll LCM(ll a, ll b)

{

    ll g = __gcd(a,b);

    return (a*b)/g ;

}

string numtostr(ll n)

{

    ostringstream str1 ;

    str1 << n ;

    return str1.str();

}

ll strtonum(string s)

{

    ll x ;

    stringstream str1(s);

    str1 >> x ;

    return x ;

}

int h1,m1,h2,m2,a;

int main(void)

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    cin>>h1>>m1>>h2>>m2>>a;

    cout<<h2*60+m2-(h1*60+m1)-a<<'\n';

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.428807965963062x):
#include <stdio.h>

#include <string.h>



#define ll long long int

#define fl(i,n) for(int i = 0; i < (n); i++)

#define fls(i,s) for(int i = 0; s[i] != '\0'; i++)



int main() {

    int h1,m1,h2,m2,k;

    scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);

    int duration;

    if(h1 > h2){

        duration = ((h1-h2)*60) + m1-m2;

    }else if(h2 > h1){

        duration = ((h2-h1)*60) + m2-m1;

    }else{

        if(m1 > m2){

            duration = (m1-m2);

        }else{

            duration = (m2-m1);

        }

    }

    duration -= k;

    printf("%d\n", duration);

    

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	int h1, m1, h2, m2; cin >> h1 >> m1 >> h2 >> m2;

	int k; cin >> k;

	cout << (h2 * 60 + m2 - h1 * 60 - m1 - k) << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.309374136587708x):
#include <stdio.h>

#include <string.h>



#define ll long long int

#define fl(i,n) for(int i = 0; i < (n); i++)

#define fls(i,s) for(int i = 0; s[i] != '\0'; i++)



int main() {

    int h1,m1,h2,m2,k;

    scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);

    int duration;

    if(h1 > h2){

        duration = ((h1-h2)*60) + m1-m2;

    }else if(h2 > h1){

        duration = ((h2-h1)*60) + m2-m1;

    }else{

        if(m1 > m2){

            duration = (m1-m2);

        }else{

            duration = (m2-m1);

        }

    }

    duration -= k;

    printf("%d\n", duration);

    

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back

#define pi (acos(-1))

#define ull  unsigned long long

#define ld long double

///freopen("input.txt","r",stdin);

///freopen("output.txt","w",stdout);

#define M 100000

ll LCM(ll a, ll b)

{

    ll g = __gcd(a,b);

    return (a*b)/g ;

}

string numtostr(ll n)

{

    ostringstream str1 ;

    str1 << n ;

    return str1.str();

}

ll strtonum(string s)

{

    ll x ;

    stringstream str1(s);

    str1 >> x ;

    return x ;

}

int h1,m1,h2,m2,a;

int main(void)

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    cin>>h1>>m1>>h2>>m2>>a;

    cout<<h2*60+m2-(h1*60+m1)-a<<'\n';

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.442803333324356x):
#include<stdio.h>



int main(){

	int N;

	int n1;

	int M;

	int m1;

	int k;

	scanf("%d %d %d %d %d",&N ,&n1,&M,&m1,&k );

	int waktu = ((M*60+m1)-(N*60+n1))-k;

	printf ("%d",waktu);

	

	

	

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	int h1, m1, h2, m2; cin >> h1 >> m1 >> h2 >> m2;

	int k; cin >> k;

	cout << (h2 * 60 + m2 - h1 * 60 - m1 - k) << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.3230616057275215x):
#include<stdio.h>



int main(){

	int N;

	int n1;

	int M;

	int m1;

	int k;

	scanf("%d %d %d %d %d",&N ,&n1,&M,&m1,&k );

	int waktu = ((M*60+m1)-(N*60+n1))-k;

	printf ("%d",waktu);

	

	

	

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back

#define pi (acos(-1))

#define ull  unsigned long long

#define ld long double

///freopen("input.txt","r",stdin);

///freopen("output.txt","w",stdout);

#define M 100000

ll LCM(ll a, ll b)

{

    ll g = __gcd(a,b);

    return (a*b)/g ;

}

string numtostr(ll n)

{

    ostringstream str1 ;

    str1 << n ;

    return str1.str();

}

ll strtonum(string s)

{

    ll x ;

    stringstream str1(s);

    str1 >> x ;

    return x ;

}

int h1,m1,h2,m2,a;

int main(void)

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    cin>>h1>>m1>>h2>>m2>>a;

    cout<<h2*60+m2-(h1*60+m1)-a<<'\n';

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.4280605315355706x):
#include<stdio.h>



int main()

{

    int h1,h2,m1,m2,k;

    scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k);

    m1+=60*h1;

    m2+=60*h2;

    printf("%d\n",m2-m1-k);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	int h1, m1, h2, m2; cin >> h1 >> m1 >> h2 >> m2;

	int k; cin >> k;

	cout << (h2 * 60 + m2 - h1 * 60 - m1 - k) << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.308643145725073x):
#include<stdio.h>



int main()

{

    int h1,h2,m1,m2,k;

    scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k);

    m1+=60*h1;

    m2+=60*h2;

    printf("%d\n",m2-m1-k);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back

#define pi (acos(-1))

#define ull  unsigned long long

#define ld long double

///freopen("input.txt","r",stdin);

///freopen("output.txt","w",stdout);

#define M 100000

ll LCM(ll a, ll b)

{

    ll g = __gcd(a,b);

    return (a*b)/g ;

}

string numtostr(ll n)

{

    ostringstream str1 ;

    str1 << n ;

    return str1.str();

}

ll strtonum(string s)

{

    ll x ;

    stringstream str1(s);

    str1 >> x ;

    return x ;

}

int h1,m1,h2,m2,a;

int main(void)

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    cin>>h1>>m1>>h2>>m2>>a;

    cout<<h2*60+m2-(h1*60+m1)-a<<'\n';

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.42875426232482x):
#include <stdio.h>



int main(){

	int H1, M1, H2, M2, K;

	scanf("%d %d %d %d %d",&H1, &M1, &H2, &M2, &K);

	

	int hours = H2 - H1;

	int minutes = M2 - M1;

	

	int sum = (hours * 60) + minutes;

	int total = sum - K;

	

	printf("%d\n", total);

	

	

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	int h1, m1, h2, m2; cin >> h1 >> m1 >> h2 >> m2;

	int k; cin >> k;

	cout << (h2 * 60 + m2 - h1 * 60 - m1 - k) << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.309321614430043x):
#include <stdio.h>



int main(){

	int H1, M1, H2, M2, K;

	scanf("%d %d %d %d %d",&H1, &M1, &H2, &M2, &K);

	

	int hours = H2 - H1;

	int minutes = M2 - M1;

	

	int sum = (hours * 60) + minutes;

	int total = sum - K;

	

	printf("%d\n", total);

	

	

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

 

using namespace std;

using namespace __gnu_pbds;

 

#define fi first

#define se second

#define mp make_pair

#define pb push_back

#define fbo find_by_order

#define ook order_of_key

 

typedef long long ll;

typedef pair<ll,ll> ii;

typedef vector<int> vi;

typedef long double ld; 

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

typedef set<int>::iterator sit;

typedef map<int,int>::iterator mit;

typedef vector<int>::iterator vit;

 

int par[100001];

vi adj[100001];

int dp[100001];

 

void dfs(int u)

{

	vi vec;

	for(int i = 0; i < adj[u].size(); i++)

	{

		int v = adj[u][i];

		dfs(v);

		vec.pb(dp[v]);

	}

	sort(vec.begin(),vec.end());

	dp[u] = 0;

	for(int i = 0; i < vec.size(); i++)

	{

		int t = vec[i];

		if(dp[u]<t+1) dp[u]=t+1;

		else

		{

			dp[u]++;

		}

	}

	//cerr<<u<<' '<<dp[u]<<'\n';

}

 

int main()

{

	ios_base::sync_with_stdio(0); cin.tie(0);

	int n; cin>>n;

	for(int i = 1; i < n; i++) 

	{

		cin>>par[i];

		par[i]--;

		adj[par[i]].pb(i);

	}

	dfs(0);

	cout<<dp[0]<<'\n';

}

// Faster C++ solution for the same problem (measured speedup: 3.5753067187093186x):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

#define MAXN 200002

int n;

struct node

{

	int to,next;

}a[MAXN];

int f[MAXN],b[MAXN],head[MAXN];

bool cmp(int a,int b)

{

	return a>b;

}

void dfs(int u)

{

	int s=0,minn=0;

	for(int i=head[u];~i;i=a[i].next)

		dfs(a[i].to);

	for(int i=head[u];~i;i=a[i].next)

		b[++s]=f[a[i].to];

	if(s==0)return;

	sort(b+1,b+s+1,cmp);

	for(int i=1;i<=s;i++)

		minn=max(minn,i+b[i]);

	f[u]=minn;

}

int main()

{

	memset(head,-1,sizeof(head));

	scanf("%d",&n);

	int x;

	for(int i=2;i<=n;i++)

	{

		scanf("%d",&x);

		a[i]=(node){i,head[x]};

		head[x]=i;

	}

	dfs(1);

	printf("%d",f[1]);

}
// Slower C++ solution:
#include<cstdio>

#include<vector>

#include<algorithm>

#include<functional>

using namespace std;



#define MAXN 100000

int N;

int Height[MAXN+5];

vector<int> G[MAXN+5];



bool cmp(int x,int y){

    return Height[x]>Height[y];

}

void dfs(int u){

    for(int i=0;i<int(G[u].size());i++)

        dfs(G[u][i]);

    sort(G[u].begin(),G[u].end(),cmp);

    for(int i=0;i<int(G[u].size());i++)

        Height[u]=max(Height[u],Height[G[u][i]]+i+1);

}



int main(){

    scanf("%d",&N);

    for(int i=2;i<=N;i++){

        int fa;

        scanf("%d",&fa);

        G[fa].push_back(i);

    }

    dfs(1);

    printf("%d",Height[1]);

}


// Faster C++ solution for the same problem (measured speedup: 3.456474333219966x):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

#define MAXN 200002

int n;

struct node

{

	int to,next;

}a[MAXN];

int f[MAXN],b[MAXN],head[MAXN];

bool cmp(int a,int b)

{

	return a>b;

}

void dfs(int u)

{

	int s=0,minn=0;

	for(int i=head[u];~i;i=a[i].next)

		dfs(a[i].to);

	for(int i=head[u];~i;i=a[i].next)

		b[++s]=f[a[i].to];

	if(s==0)return;

	sort(b+1,b+s+1,cmp);

	for(int i=1;i<=s;i++)

		minn=max(minn,i+b[i]);

	f[u]=minn;

}

int main()

{

	memset(head,-1,sizeof(head));

	scanf("%d",&n);

	int x;

	for(int i=2;i<=n;i++)

	{

		scanf("%d",&x);

		a[i]=(node){i,head[x]};

		head[x]=i;

	}

	dfs(1);

	printf("%d",f[1]);

}
// Slower C++ solution:
#include<cstdio>

#include<map>

#include<algorithm>

#include<vector>

using namespace std;

#define MAXN 100005

int n,t[MAXN];

vector<int> G[MAXN];

void dfs(int u,int f)

{

	map<int,int> cnt;

	for(int i=0;i<G[u].size();i++)

	{

		int v=G[u][i];

		if(v==f) continue;

		dfs(v,u);

		cnt[t[v]]++;

	}

	map<int,int>::iterator it;

	for(it=cnt.begin();it!=cnt.end();it++)

		if(it->second>1)

			cnt[(it->first)+1]+=it->second-1;

	if(it!=cnt.begin())

		it--,t[u]=it->first+1;

}

int main()

{

	scanf("%d",&n);

	for(int i=2;i<=n;i++)

	{

		int x;

		scanf("%d",&x);

		G[i].push_back(x);

		G[x].push_back(i);

	}

	dfs(1,0);

	printf("%d\n",t[1]);

}

// Faster C++ solution for the same problem (measured speedup: 3.466472098815444x):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

#define MAXN 200002

int n;

struct node

{

	int to,next;

}a[MAXN];

int f[MAXN],b[MAXN],head[MAXN];

bool cmp(int a,int b)

{

	return a>b;

}

void dfs(int u)

{

	int s=0,minn=0;

	for(int i=head[u];~i;i=a[i].next)

		dfs(a[i].to);

	for(int i=head[u];~i;i=a[i].next)

		b[++s]=f[a[i].to];

	if(s==0)return;

	sort(b+1,b+s+1,cmp);

	for(int i=1;i<=s;i++)

		minn=max(minn,i+b[i]);

	f[u]=minn;

}

int main()

{

	memset(head,-1,sizeof(head));

	scanf("%d",&n);

	int x;

	for(int i=2;i<=n;i++)

	{

		scanf("%d",&x);

		a[i]=(node){i,head[x]};

		head[x]=i;

	}

	dfs(1);

	printf("%d",f[1]);

}
// Slower C++ solution:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

 

using namespace std;

using namespace __gnu_pbds;

 

#define fi first

#define se second

#define mp make_pair

#define pb push_back

#define fbo find_by_order

#define ook order_of_key

 

typedef long long ll;

typedef pair<ll,ll> ii;

typedef vector<int> vi;

typedef long double ld; 

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

typedef set<int>::iterator sit;

typedef map<int,int>::iterator mit;

typedef vector<int>::iterator vit;

 

int par[100001];

vi adj[100001];

int dp[100001];

 

void dfs(int u)

{

	vi vec;

	for(int i = 0; i < adj[u].size(); i++)

	{

		int v = adj[u][i];

		dfs(v);

		vec.pb(dp[v]);

	}

	sort(vec.begin(),vec.end());

	dp[u] = 0;

	for(int i = 0; i < vec.size(); i++)

	{

		int t = vec[i];

		if(dp[u]<t+1) dp[u]=t+1;

		else

		{

			dp[u]++;

		}

	}

	//cerr<<u<<' '<<dp[u]<<'\n';

}

 

int main()

{

	ios_base::sync_with_stdio(0); cin.tie(0);

	int n; cin>>n;

	for(int i = 1; i < n; i++) 

	{

		cin>>par[i];

		par[i]--;

		adj[par[i]].pb(i);

	}

	dfs(0);

	cout<<dp[0]<<'\n';

}

// Faster C++ solution for the same problem (measured speedup: 3.57345976673875x):
#include <bits/stdc++.h>

using namespace std;



typedef pair <int, int> P;



const int N = 1e5 + 10;



int dp[N], p[N], deg[N];

priority_queue <P, vector <P>, greater <P> > pq;



int main(){

	int n, id;

	scanf("%d",&n);

	for (int i = 2; i <= n; i++){

		scanf("%d",&p[i]);

		deg[p[i]]++;

	}

	for (int i = 1; i <= n; i++){

		if (!deg[i]) pq.push({0, i});

	}

	while (!pq.empty()){

		id = pq.top().second; pq.pop();

		dp[p[id]] = max(dp[p[id]], dp[id]) + 1;

		if (--deg[p[id]] == 0) pq.push({dp[p[id]], p[id]});

	}

	printf("%d\n", dp[1]);

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<vector>

#include<algorithm>

#include<functional>

using namespace std;



#define MAXN 100000

int N;

int Height[MAXN+5];

vector<int> G[MAXN+5];



bool cmp(int x,int y){

    return Height[x]>Height[y];

}

void dfs(int u){

    for(int i=0;i<int(G[u].size());i++)

        dfs(G[u][i]);

    sort(G[u].begin(),G[u].end(),cmp);

    for(int i=0;i<int(G[u].size());i++)

        Height[u]=max(Height[u],Height[G[u][i]]+i+1);

}



int main(){

    scanf("%d",&N);

    for(int i=2;i<=N;i++){

        int fa;

        scanf("%d",&fa);

        G[fa].push_back(i);

    }

    dfs(1);

    printf("%d",Height[1]);

}


// Faster C++ solution for the same problem (measured speedup: 3.454688768348691x):
#include <bits/stdc++.h>

using namespace std;



typedef pair <int, int> P;



const int N = 1e5 + 10;



int dp[N], p[N], deg[N];

priority_queue <P, vector <P>, greater <P> > pq;



int main(){

	int n, id;

	scanf("%d",&n);

	for (int i = 2; i <= n; i++){

		scanf("%d",&p[i]);

		deg[p[i]]++;

	}

	for (int i = 1; i <= n; i++){

		if (!deg[i]) pq.push({0, i});

	}

	while (!pq.empty()){

		id = pq.top().second; pq.pop();

		dp[p[id]] = max(dp[p[id]], dp[id]) + 1;

		if (--deg[p[id]] == 0) pq.push({dp[p[id]], p[id]});

	}

	printf("%d\n", dp[1]);

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<map>

#include<algorithm>

#include<vector>

using namespace std;

#define MAXN 100005

int n,t[MAXN];

vector<int> G[MAXN];

void dfs(int u,int f)

{

	map<int,int> cnt;

	for(int i=0;i<G[u].size();i++)

	{

		int v=G[u][i];

		if(v==f) continue;

		dfs(v,u);

		cnt[t[v]]++;

	}

	map<int,int>::iterator it;

	for(it=cnt.begin();it!=cnt.end();it++)

		if(it->second>1)

			cnt[(it->first)+1]+=it->second-1;

	if(it!=cnt.begin())

		it--,t[u]=it->first+1;

}

int main()

{

	scanf("%d",&n);

	for(int i=2;i<=n;i++)

	{

		int x;

		scanf("%d",&x);

		G[i].push_back(x);

		G[x].push_back(i);

	}

	dfs(1,0);

	printf("%d\n",t[1]);

}

// Faster C++ solution for the same problem (measured speedup: 3.464681369242418x):
#include <bits/stdc++.h>

using namespace std;



typedef pair <int, int> P;



const int N = 1e5 + 10;



int dp[N], p[N], deg[N];

priority_queue <P, vector <P>, greater <P> > pq;



int main(){

	int n, id;

	scanf("%d",&n);

	for (int i = 2; i <= n; i++){

		scanf("%d",&p[i]);

		deg[p[i]]++;

	}

	for (int i = 1; i <= n; i++){

		if (!deg[i]) pq.push({0, i});

	}

	while (!pq.empty()){

		id = pq.top().second; pq.pop();

		dp[p[id]] = max(dp[p[id]], dp[id]) + 1;

		if (--deg[p[id]] == 0) pq.push({dp[p[id]], p[id]});

	}

	printf("%d\n", dp[1]);

	return 0;

}