Output-sensitive algorithm
 
x
OK