{"raw_statement":[{"iden":"statement","content":"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_.\n\nOnce 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.\n\nHelp Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest."},{"iden":"input","content":"First line of input contains single integer number _n_ (2 ≤ _n_ ≤ 100 000) — number of inflorescences.\n\nSecond 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."},{"iden":"output","content":"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."},{"iden":"examples","content":"Input\n\n3\n1 1\n\nOutput\n\n1\n\nInput\n\n5\n1 2 2 2\n\nOutput\n\n3\n\nInput\n\n18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n\nOutput\n\n4"},{"iden":"note","content":"In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.\n\nIn the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2\\-nd inflorescence to 1st one in the next second and Arcady will collect it."}],"translated_statement":[{"iden":"statement","content":"在 Arcady 的花园里生长着一棵奇特的苹果树，每年只结果一次。它的特殊性可以用以下方式解释：树上有 #cf_span[n] 个花序，编号从 #cf_span[1] 到 #cf_span[n]。编号为 #cf_span[1] 的花序位于树干基部，而其他编号为 #cf_span[i]（#cf_span[i > 1]）的花序则位于枝条顶端，该枝条的底部是 #cf_span[pi]-th 花序，且 #cf_span[pi < i]。\n\n当树开始结果时，每个花序中恰好出现一个苹果。就在苹果出现的同时，它们开始沿着枝条向树干基部滚动。每一秒，除了位于第一个花序的苹果外，所有苹果同时向下滚动一个枝条，例如，位于 #cf_span[a]-th 花序的苹果会移动到 #cf_span[pa]-th 花序。到达第一个花序的苹果会在同一时刻被 Arcady 采集。这棵树的另一个特殊性是：一旦两个苹果出现在同一个花序中，它们就会*湮灭*。每一对苹果都会发生湮灭，例如，如果同一时刻某个花序中有 #cf_span[5] 个苹果，则只有一个不会被湮灭；如果有 #cf_span[8] 个苹果，则所有苹果都会被湮灭。因此，在任何时刻，每个花序中最多只能有一个苹果。\n\n请帮助 Arcady 计算他在一次收获中能从第一个花序中收集到的苹果数量。\n\n输入的第一行包含一个整数 #cf_span[n]（#cf_span[2 ≤ n ≤ 100 000]）——花序的数量。\n\n输入的第二行包含一个包含 #cf_span[n - 1] 个整数的序列 #cf_span[p2, p3, ..., pn]（#cf_span[1 ≤ pi < i]），其中 #cf_span[pi] 表示从第 #cf_span[i] 个花序滚下的苹果将到达的花序编号。\n\n输出应为一行，包含一个整数：Arcady 在一次收获中能从第一个花序中收集到的苹果数量。\n\n在第一个例子中，Arcady 只能收集最初位于第 #cf_span[1] 个花序中的一个苹果。下一秒，来自第 #cf_span[2] 和 #cf_span[3] 个花序的苹果会滚下并相互湮灭，Arcady 将无法收集它们。\n\n在第二个例子中，Arcady 将能收集 3 个苹果。第一个是最初位于第一个花序中的苹果。一秒后，来自第 #cf_span[2] 个花序的苹果滚到第 #cf_span[1] 个花序（Arcady 将收集它），而来自第 #cf_span[3]、#cf_span[4]、#cf_span[5] 个花序的苹果滚到第 #cf_span[2] 个花序。其中两个相互湮灭，剩下一个未被湮灭的苹果在下一秒从第 #cf_span[2] 个花序滚到第 #cf_span[1] 个花序，Arcady 将收集它。"},{"iden":"input","content":"输入的第一行包含一个整数 #cf_span[n]（#cf_span[2 ≤ n ≤ 100 000]）——花序的数量。第二行包含一个包含 #cf_span[n - 1] 个整数的序列 #cf_span[p2, p3, ..., pn]（#cf_span[1 ≤ pi < i]），其中 #cf_span[pi] 表示从第 #cf_span[i] 个花序滚下的苹果将到达的花序编号。"},{"iden":"output","content":"输出应为一行，包含一个整数：Arcady 在一次收获中能从第一个花序中收集到的苹果数量。"},{"iden":"examples","content":"输入\n3\n1 1\n输出\n1\n\n输入\n5\n1 2 2 2\n输出\n3\n\n输入\n18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n输出\n4"},{"iden":"note","content":"在第一个例子中，Arcady 只能收集最初位于第 #cf_span[1] 个花序中的一个苹果。下一秒，来自第 #cf_span[2] 和 #cf_span[3] 个花序的苹果会滚下并相互湮灭，Arcady 将无法收集它们。在第二个例子中，Arcady 将能收集 3 个苹果。第一个是最初位于第一个花序中的苹果。一秒后，来自第 #cf_span[2] 个花序的苹果滚到第 #cf_span[1] 个花序（Arcady 将收集它），而来自第 #cf_span[3]、#cf_span[4]、#cf_span[5] 个花序的苹果滚到第 #cf_span[2] 个花序。其中两个相互湮灭，剩下一个未被湮灭的苹果在下一秒从第 #cf_span[2] 个花序滚到第 #cf_span[1] 个花序，Arcady 将收集它。"}],"sample_group":[],"show_order":[],"formal_statement":"Let $ n $ be the number of inflorescences, numbered $ 1 $ to $ n $, with inflorescence $ 1 $ as the root. For each $ i \\in \\{2, 3, \\dots, n\\} $, let $ p_i \\in \\{1, 2, \\dots, i-1\\} $ denote the parent of inflorescence $ i $, defining a tree structure.\n\nInitially, one apple is present at each inflorescence. At each second, every apple not at the root moves to its parent. When multiple apples arrive at the same inflorescence at the same time, they annihilate in pairs: an even number of apples annihilates completely; an odd number leaves one apple.\n\nDefine $ d_i $ as the depth of inflorescence $ i $, i.e., the number of edges on the unique path from $ i $ to the root (so $ d_1 = 0 $).\n\nLet $ c_t $ be the number of apples that reach the root at time $ t $. Since apples from inflorescence $ i $ reach the root at time $ d_i $, we consider the multiset of depths $ \\{ d_i \\mid i = 1, 2, \\dots, n \\} $.\n\nAt each time $ t $, let $ a_t $ be the number of inflorescences with depth $ t $. Then, the number of apples arriving at the root at time $ t $ is $ a_t \\mod 2 $, due to pairwise annihilation.\n\nThe total number of apples collected is the sum over all times $ t $ of the parity of apples arriving at that time:\n\n$$\n\\sum_{t=0}^{\\max_i d_i} (a_t \\mod 2)\n$$\n\nThus, the problem reduces to:  \nGiven a tree with $ n $ nodes rooted at node 1, compute the number of depth levels $ t $ for which the number of nodes at depth $ t $ is odd.\n\n---\n\n**Formal Statement:**\n\nLet $ T = (V, E) $ be a rooted tree with $ |V| = n $, root $ r = 1 $, and parent function $ p: V \\setminus \\{1\\} \\to V $ given as input.\n\nDefine the depth function $ d: V \\to \\mathbb{N}_0 $ by:\n- $ d(1) = 0 $\n- $ d(i) = d(p_i) + 1 $ for $ i = 2, \\dots, n $\n\nFor each $ t \\in \\mathbb{N}_0 $, let:\n$$\na_t = |\\{ i \\in V \\mid d(i) = t \\}|\n$$\n\nCompute:\n$$\n\\sum_{t=0}^{\\infty} (a_t \\mod 2)\n$$\n\nThis sum is finite since $ a_t = 0 $ for $ t > \\max_i d(i) $.\n\n**Output:** The value of the above sum.","simple_statement":null,"has_page_source":false}