1: Uncheck Flatten first in the Displacement section of the terrain node.
2: Plan your masks.... the sum of all masks at every point must = 1. Sounds obvious, but when you get errors, this is the first thing to check, especially with function-based masks.
For 2 terrains this is easy.
a) Use the mask for the smaller terrain as its blending shader.
b) Apply the same mask to the larger terrain but invert it.
For 3 terrains
repeat step a) above
Then subtract the mask for the smaller terrain from the mask for the larger terrain (subtract scalar node) and use this as the blending shader for the larger terrain
Then apply the same mask of the second largest terrain to the 3rd terrain and invert it.
The pattern scales for as many terrains as you want, with the largest terrain using an inverted mask from the second largest terrain.