private const val MOD = 1000000007 @JvmInline @Suppress("NOTHING_TO_INLINE") private value class ModInt(val x: Int) { inline operator fun plus(other: ModInt) = ModInt((x + other.x).let { if (it >= MOD) it - MOD else it }) inline operator fun minus(other: ModInt) = ModInt((x - other.x).let { if (it < 0) it + MOD else it }) inline operator fun times(other: ModInt) = ModInt((x.toLong() * other.x % MOD).toInt()) companion object { inline fun from(x: Int) = ModInt((x % MOD + MOD) % MOD) inline fun from(x: Long) = ModInt(((x % MOD).toInt() + MOD) % MOD) } } @JvmInline private value class ModIntArray(private val storage:IntArray) { operator fun get(index: Int) = ModInt(storage[index]) operator fun set(index: Int, value: ModInt) { storage[index] = value.x } val size get() = storage.size } private inline fun ModIntArray(n: Int, init: (Int) -> ModInt) = ModIntArray(IntArray(n) { init(it).x }) fun main() { val n = readInt() val dp = Array(n) { ModIntArray(n + 1) { ModInt.from(if (it == 1) 1 else 0) } } val p = List(n) { if (it == 0) -1 else readInt() } val size = IntArray(n) { 1 } for (v in n - 1 downTo 1) { for (size_p in size[p[v]] downTo 0) { for (size_my in 1..size[v]) { dp[p[v]][size_my + size_p] += dp[p[v]][size_p] * dp[v][size_my] } } size[p[v]] += size[v] } for (i in 1 .. n) { println(dp.fold(ModInt.from(0)) { acc, it -> acc + it[i] }.x) } } private fun readInt() = readln().toInt()