Count tree in python