#P9166. Magic

Magic

Source: Super League of Chinese College Students Algorithm Design 2022, Contest 4 by BIT.