package main import ( "bufio" "fmt" "os" "strconv" ) func main() { var n int _, _ = fmt.Scan(&n) bs := bufio.NewScanner(os.Stdin) bs.Split(bufio.ScanWords) nums := make(map[int]int, 0) // 数字がどこにあるか for i := 0; i < n; i++ { bs.Scan() a, _ := strconv.Atoi(bs.Text()) nums[a] = i } // fmt.Println(nums) cnt := 0 fix := 0 for { end := true for i := n - fix; i > 1; i-- { if nums[i] > nums[i-1] { fix++ } else { end = false cnt++ for j := 1; j <= n; j++ { if nums[j] < nums[i-1] { nums[j]++ } } nums[i-1] = 0 // fmt.Println(cnt, fix, nums) } } if end { break } } fmt.Println(cnt) }