using System; using System.Linq; using System.Collections.Generic; namespace yukicoder { class PG { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var blocks = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList(); var compBlocks = new List(blocks); compBlocks = compBlocks.OrderBy(c => c).ToList(); int ans = 0; int i = N - 1; while(i >= 0) { if(compBlocks[i] == blocks[i]) { i--; continue; } int max = -1; int maxIndex = -1; for(int p = i ;p >= 0;p--)//入れ替え元探索 { if(blocks[p] == compBlocks[i]) { break; }else if(max < blocks[p]) { max = blocks[p]; maxIndex = p; } } for(int q = maxIndex;q > 0;q--)//入れ替え { blocks[q] = blocks[q - 1]; } blocks[0] = max; ans++; } Console.WriteLine(ans); } } }