human
I found an interesting problem on https://codeforces.com/problemset/problem/930/A:
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is p_{i}-th inflorescence and p_{i} < i.

Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to p_{a}-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.

Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.

-----Input-----

First line of input contains single integer number n (2 ≤ n ≤ 100 000)  — number of inflorescences.

Second line of input contains sequence of n - 1 integer numbers p_2, p_3, ..., p_{n} (1 ≤ p_{i} < i), where p_{i} is number of inflorescence into which the apple from i-th inflorescence rolls down.

-----Output-----

Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.

-----Examples-----
Input
3
1 1

Output
1

Input
5
1 2 2 2

Output
3

Input
18
1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4

Output
4


-----Note-----

In first example Arcady will be able to collect only one apple, initially...

I tried it in Python, but could not do it. Can you solve it?

Give me a the Python code you requested?
assistant
#Here is the Python code you requested.

import threading
from sys import setrecursionlimit, exc_info

def main():
    try:
        n = int(input())
        par = list(map(int, input().split()))

        gr = [[] for i in range(n)]
        for i in range(n - 1):
            gr[par[i] - 1].append(i + 1)

        cnt = [0] * n


        def dfs(v, depth=0):
            cnt[depth] += 1
            while depth >= len(cnt):
                pass
            for u in gr[v]:
                dfs(u, depth + 1)


        dfs(0)
        print(sum([x % 2 for x in cnt]))
    except:
        print(exc_info()[0])

setrecursionlimit(100000000)
threading.stack_size(102400000)
thread = threading.Thread(target=main)
thread.start()