The distance between a 16 foot tall flagpole and a 40 foot tall tree is equal to the sum of the lengths of their shadows. If the flagpole casts a 18 foot shadow, find the distance from the flagpole to the tree.