the girl name Masha walking forest find complete binary tree height n permutation p length m2na complete binary tree height n rooted tree vertex leave exactly son length path root leave n the picture show complete binary tree n2A permutation array consist n different integer 1 n for example 23154 permutation 122 2 occur twice 134 permutation n3 4 arraylet enumerate m leave tree leave right the leaf number contain value p_i 1 le le mFor example n 2 p 3 1 4 2 tree look like Masha consider tree beautiful value leave order leave right increase orderIn operation Masha choose nonleaf vertex tree swap leave right son subtreesfor example Masha apply operation root tree discuss follow form help Masha understand tree beautiful certain number operation if output minimum number operation tree beautiful