Find Subtree Sizes After Changes
Each node moves under its nearest ancestor with the same letter; subtree sizes are then summed bottom-up, since parents always come earlier.
Each node moves under its nearest ancestor with the same letter; subtree sizes are then summed bottom-up, since parents always come earlier.