How can I accept the input

I wanted to know how can I make the buildTree() function to take the input. Like I at least wanted to know based on the input given how the BT is constructed.
With context to this:
1 2
2 2
3 0
4 0
5 2
6 0
7 0
2

Output:
20

Hey it is like
Level 0: 1
Level 1: 2 5
Level 2: 3 4 6 7
You can think of it as 1 has 2 children
Then 2 has 2 children (with 1 as root)
Then follow children of 2 which are leaf nodes
Then comes second child of 1 i.e 5 which has 2 children
Finally we have 2 children of 5 that are 6 and 7 which are leaf nodes
At last level is given and that is 2 so sum at level 2 is 20…

Hi sagnik
I am marking your doubt as resolved. You can reopen it if you feel so

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.