Under construction

Still being built. Things may change

Prime Tree

Time limit2sMemory limit512 MB

Summary
Given a rooted tree with n nodes, find the largest number of prime trees whose tree product equals it.
Level

Hard8 of 10

Topics
Tree, Number theory, DFS
Solved
No attempts yet

Problem

Bobo proposes a multiplication operation on rooted trees.

Let AA and BB be two arbitrary rooted trees. Then T=A⋅BT = A \cdot B is built by making a copy of BB for each vertex x∈Ax \in A and merging the root of this copy with xx (see the following figure for more details).

Apparently, T⋅1=1⋅T=TT \cdot \mathbf{1} = \mathbf{1} \cdot T = T, where 1\mathbf{1} is the rooted tree with only one vertex. So, 1\mathbf{1} is a factor of every rooted tree, and every rooted tree is a factor of itself. If a rooted tree TT has only TT and 1\mathbf{1} as its factors, we call TT a prime tree.

Bobo has a rooted tree TT with nn nodes, labeled 1,2,…,n1, 2, \dots, n. He wants to factor TT into a product of as many prime trees as possible. That is, find an equation T=T1⋅T2⋯TmT = T_1 \cdot T_2 \cdots T_m where each TiT_i (1≤i≤m1 \leq i \leq m) is a prime tree and mm is maximum.

Note that 1\mathbf{1} is not a prime tree.

Input

The input contains zero or more test cases, and is terminated by end-of-file. For each test case:

The first line contains an integer nn, the number of nodes (2≤n≤1062 \leq n \leq 10^6).

The second line contains n−1n - 1 integers p2,p3,…,pnp_2, p_3, \dots, p_n, where pip_i is the parent of the ii-th node (1≤pi≤i−11 \leq p_i \leq i - 1).

It is guaranteed that the sum of all nn does not exceed 10610^6.

Output

For each test case, output an integer denoting the maximum number of prime factors.

Examples1

  1. Example 1

    Input
    12
    1 1 1 1 2 2 4 5 5 6 10
    3
    1 1
    6
    1 1 1 2 3
    13
    1 1 1 2 2 3 3 4 5 6 7 8
    
    Expected output
    3
    1
    2
    1