[BOJ 13148] Correcting Cheeseburgers
View as PDFCheeseburgers are serious business. They are the most delicious food on earth, but there is a lot of room for error when making a cheeseburger. Even otherwise capable cooks often mess up the order of the assembled ingredients.</p>
The only correct order of ingredients between the buns is, of course, as following from top to bottom:
- Ketchup & Mustard
- Beef Tomato
- Pickles
- Red Onions
- Cheddar Cheese
- Garlic
- Salt & Pepper
- Beef Patty, medium grilled
- Corn Salad
- Mayonnaise
Any deviation from this order is completely unacceptable. Therefore it is sometimes necessary to reassemble a cheeseburger.
Space on an average plate and social norms are rather restrictive when it comes to operating on a cheeseburger. The only feasible operation is the bit-shuffle (burger-ineptly-transformed). The bit-shuffle separates the entire burger into four parts of contiguous ingredients a, b, c and d and arranges them in the new order c a d b. The size of each of the four parts is selectable and may be zero.
Since the burger cools rapidly we are interested in the minimum required bit-shuffles to arrive at an acceptable burger.
Each given cheeseburger consists of n unique ingredients labeled from 1 to n. The correct order is always the natural order 1 2 . . . n.

Figure B.1: Illustration of the first sample input.

Figure B.2: Illustration of the second sample input.
입력 형식
The input consists of:</p>
- one line with an integer n (1 ≤ n ≤ 10), where n is the number of ingredients used;
- one line with n integers describing the order of the ingredients of the given cheeseburger. The ingredients are numbered from 1 to n.
Output the minimum number of bit-shuffles to correct the given cheeseburger.
예제 입력 1
9
3 4 7 8 9 1 2 5 6
예제 출력 1
1
예제 입력 2
3
1 3 2
예제 출력 2
1
Comments