SOLVE
LATER
Given a Binary tree $$T$$ consisting of $$N$$ nodes rooted at node $$1$$ and a number $$K$$. each node has a number written on it, where the number written on the $$i^{th}$$ node is $$A[i]$$.
Now, Monk needs to find the number of unordered triplets $$(i,j,k)$$, such that node $$i$$ is an ancestor of node $$j$$ as well as node $$k$$, $$j \ne k$$, and $$A[i]+A[j]+A[k] \ge K$$.
A node $$x$$ is considered an ancestor of another node $$y$$ if $$x$$ is parent of $$y$$ or $$x$$ is an ancestor of parent of $$y$$.
Help Monk for the same.
Input Format :
The first line contains $$2$$ space separated integers $$N$$ and $$K$$. The next line contains $$N$$ space separated integers, where the $$i^{th}$$ integer denotes $$A[i]$$.
The next line contains $$N-1$$ space separated integers, where the $$i^{th}$$ integer represents the parent of node $$i+1$$.
Output Format :
Print the required answer on a single line.
Constraints :
$$ 1 \le N \le 500 $$
$$ 0 \le A[i] ,K \le 10^9 $$
$$ 1 \le parent[i] < i$$, where $$2 \le i \le N$$
Note :
It is guaranteed that the given input forms a valid binary tree.
Image of the tree is given below
The triplets forming part of the answer are :
$$ (1,2,3)$$
$$(1,2,4)$$
$$(1,2,5)$$
$$ (1,3,4)$$
$$(1,3,5)$$.
$$ (1,4,5)$$.
$$ (2,3,4)$$