题目描述
Problem Description
Takahashi is the president of a company with $ N $ employees. The salary in Takahashi's company is determined as follows:
- All employees, including Takahashi, have employee numbers from $ 1 $ to $ N $. Takahashi's employee number is, of course, $ 1 $.
- Each employee, except Takahashi, has exactly one supervisor with a smaller employee number. An employee who is supervised by another is called a direct subordinate.
- The salary of an employee with no direct subordinates is $ 1 $. The salary of an employee with direct subordinates is ${\rm\ max}(the salaries of that employee's direct subordinates)\ +\ {\rm\ min}(the salaries of that employee's direct subordinates)\ +\ 1$. If an employee has only one direct subordinate, their salary is $ 2 $ times the subordinate's salary + $ 1 $.
Determine Takahashi's salary.
Input Format
The input is given from the standard input in the following format:
$ N $ $ B_2 $ $ B_3 $ : $ B_N $
- The first line contains an integer $N\ (1≦N≦20)$, representing the number of employees.
- The next $ N-1 $ lines contain the supervisor information for each employee. The $ i $-th line contains an integer $ B_i(1≦B_i≦i) $, representing the employee number of the supervisor of the employee with employee number $i\ +\ 1$.
Output Format
Output Takahashi's salary in one line. End the output with a newline.
Sample Input and Output
Sample Input #1
5
1
1
1
1
Sample Output #1
3
Sample Input #2
7
1
1
2
2
3
3
Sample Output #2
7
Sample Input #3
6
1
2
3
3
2
Sample Output #3
11
Sample Input #4
10
1
2
3
4
5
6
7
8
9
Sample Output #4
1023
Notes/Hints
Sample Explanation 1
Takahashi has $ 4 $ direct subordinates, all of whom have a salary of $ 1 $. Therefore, Takahashi's salary is $1\ +\ 1\ +\ 1\ =\ 3$.
Sample Explanation 2
The employees with employee numbers $ 2 $ and $ 3 $ each have two subordinates, and Takahashi is their supervisor. Since the salaries of the other employees are $ 1 $, the salaries of the employees with employee numbers $ 2 $ and $ 3 $ are $1\ +\ 1\ +\ 1\ =\ 3$. Therefore, Takahashi's salary is $3\ +\ 3\ +\ 1\ =\ 7$.
Sample Explanation 3
Takahashi has only one direct subordinate, the employee with employee number $ 2 $. This employee has two direct subordinates with employee numbers $ 3 $ and $ 6 $. Their salaries are $ 3 $ and $ 1 $ respectively, so the salary of the employee with employee number $ 2 $ is $ 5 $. Therefore, Takahashi's salary is $5+5+1\ =\ 11$.
Sample Explanation 4
Takahashi's salary can be very large.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分