Snuke has a rooted tree with N+1 vertices.
The vertices are numbered 0 through N, and Vertex 0 is the root of the tree.
The parent of Vertex i (1 \leq i \leq N) is Vertex p_i.
Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them.
The play begins with placing one marble on some of the vertices, then proceeds as follows:
 - If there is a marble on Vertex 0, move the marble into the box.
 - Move each marble from the vertex to its parent (all at once).
 - For each vertex occupied by two or more marbles, remove all the marbles from the vertex.
 - If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play.
There are 2^{N+1} ways to place marbles on some of the vertices.
For each of them, find the number of marbles that will be in the box at the end of the play, and compute the sum of all those numbers modulo 1,000,000,007.

-----Constraints-----
 - 1 \leq N < 2 \times 10^{5}
 - 0 \leq p_i < i

-----Partial Scores-----
 - In the test set worth 400 points, N < 2{,}000.

-----Input-----
Input is given from Standard Input in the following format:
N
p_1 p_2 ... p_{N}

-----Output-----
Print the answer.

-----Sample Input-----
2
0 0

-----Sample Output-----
8

When we place a marble on both Vertex 1 and 2, there will be multiple marbles on Vertex 0 by step 2. In such a case, these marbles will be removed instead of being moved to the box.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = '\n"""\n\nhttps://atcoder.jp/contests/arc086/tasks/arc086_c\n\n対消滅する可能性があるのは同じ深さの点に置かれたビー玉だけ\n→1つも残らない or 1つだけ残るである\n\nすなわち、ある深さに関して、そのうち1つ残るのがいくつあるかを数えればよい\n\n1つだけ置く場合→絶対のこる\n2つ置く場合→絶対消える\n3つ置く場合→3つのLCAが等しくなければ残る\n\n木dpみたいにする？\ndp[0] = 一つも含んでいない場合の通り数\ndp[1] = 1つ含んでいる場合の通り数\n\ndp[0] = すべての場合 - dp[1]\ndp[1] = 1つだけ1を持っている場合\n\nで、子から親に伝播させていく…？\nマージテクで計算量削減か？\n3sだからそうっぽいな…\n3つ以上のマージ書くのだるすぎん？\n\nまたはマージの順番をどっかにメモっておく\n\nmaxd-d = indexでやる\n最長のやつにマージする\n\ndp[maxd-d][1] = 1つだけ元深さdが残っている場合の数\nc = 子の数\n\n計算量は？\nサイズは高々1しか増えないので可能っぽい\n2倍処理がまずい\n\nもっと簡潔に？\n単一のdだけで考えよう\n2倍処理なんてしない\n最後に各dに関してかければいい\n→するとマージの際に2番目の大きさだけでなんとかなる\n\n必要のないマージをしない\n両方に関係ないdは操作しない\nむしろばらつきは深い部分にだけ存在するか\n浅い部分は共通。よって-xで管理すればいいか\n\n"""\n\nimport sys\nmod = 10**9 + 7\nsys.setrecursionlimit(200000)\n\nfrom collections import deque\ndef NC_Dij(lis,start):\n\n    ret = [float("inf")] * len(lis)\n    ret[start] = 0\n    \n    q = deque([start])\n    plis = [i for i in range(len(lis))]\n\n    while len(q) > 0:\n        now = q.popleft()\n\n        for nex in lis[now]:\n\n            if ret[nex] > ret[now] + 1:\n                ret[nex] = ret[now] + 1\n                plis[nex] = now\n                q.append(nex)\n\n    return ret,plis\n\ndef inverse(a): #aのmodを法にした逆元を返す\n    return pow(a,mod-2,mod)\n\n\ndef dfs(v):\n\n    if len(lis[v]) == 0:\n        ret = [ [1,1] ]\n        return ret\n\n    else:\n\n        retlis = []\n        for nex in lis[v]:\n            nret = dfs(nex)\n            retlis.append( [len(nret),nret] )\n        retlis.sort()\n\n        #1つしかない場合マージしない\n        if len(retlis) == 1:\n            retlis[-1][1].append([1,1])\n            return retlis[-1][1]\n\n        #2つ以上の場合最大のやつにマージする\n        for revd in range(retlis[-2][0]):\n\n            zmul = 1\n            amul = 1\n            for i in range(len(retlis)-1,-1,-1):\n                if revd < retlis[i][0]:\n                    zmul *= retlis[i][1][-1-revd][0]\n                    amul *= sum(retlis[i][1][-1-revd])\n                    zmul %= mod\n                    amul %= mod\n                else:\n                    break\n\n            nsum = 0\n            for i in range(len(retlis)-1,-1,-1):\n                if revd < retlis[i][0]:\n                    nsum += zmul * inverse(retlis[i][1][-1-revd][0]) * retlis[i][1][-1-revd][1]\n                    nsum %= mod\n                else:\n                    break\n\n            retlis[-1][1][-1-revd][1] = nsum\n            retlis[-1][1][-1-revd][0] = (amul-nsum) % mod\n\n        retlis[-1][1].append([1,1])\n        return retlis[-1][1]\n\nN = int(input())\np = list(map(int,input().split()))\n\nlis = [ [] for i in range(N+1) ]\n\nfor i in range(N):\n\n    #lis[i+1].append(p[i])\n    lis[p[i]].append(i+1)\n\ndlis,plis = NC_Dij(lis,0)\nmaxd = max(dlis)\n\ndn = [0] * (maxd+1)\nfor i in dlis:\n    dn[i] += 1\n\nans = dfs(0)\n#print (dn,ans)\nA = 0\nfor i in range(maxd+1):\n    A += ans[-1-i][1] * pow(2,N+1-dn[i],mod)\n    A %= mod\nprint (A)\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14391