LearnPy Hub
← Arena
AdvancedRating 1500

Good Nodes

A node is good if no node on the path from the root to it has a larger value. The tree is given level by level with N for an empty spot. Count the good nodes.

Input

One line of values and N.

Output

One integer.

Sample 1

Input
3 1 4 3 N 1 5
Output
4

Sample 2

Input
3 3 N 4 2
Output
3
solution.py
Output appears here
Good Nodes · Python Arena problem · LearnPy Hub