# 题目

According to Wikipedia:

Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain.

Heap sort divides its input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element and moving that to the sorted region. it involves the use of a heap data structure rather than a linear-time search to find the maximum.

Now given the initial sequence of integers, together with a sequence which is a result of several iterations of some sorting method, can you tell which sorting method we are using?

### Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (≤100). Then in the next line, N integers are given as the initial sequence. The last line contains the partially sorted sequence of the N numbers. It is assumed that the target sequence is always ascending. All the numbers in a line are separated by a space.

### Output Specification:

For each test case, print in the first line either “Insertion Sort” or “Heap Sort” to indicate the method used to obtain the partial result. Then run this method for one more iteration and output in the second line the resulting sequence. It is guaranteed that the answer is unique for each test case. All the numbers in a line must be separated by a space, and there must be no extra space at the end of the line.

# 题解

## 思路

• 首先需要理解题意

• 题目意思是给两个数列，第一个数列是原数列，第二个是排序了一半的序列
• 让你判断第二个数列是用插入排序的还是堆排序的
• 并且给出再一轮后的排序
• 然后要抓两种排序的不同点

• 插入排序的特点是，前几个都是排序的，后面和原序列是一样的
• 堆排序的特点是，后面几个都是排序的，但是前面的是乱的
• 我们可以利用插入排序的特点，找到第一个从小到大排列的数，比较这个数后面的所有数和原数列是否是一样的，一样的话就说明是插入排序，否则是堆排序

• 因为插入排序一次会把下一个数移动到前面合适的位置，所以下一次排序就只要将前面n个排好的数和第n+1个数排列一下就行

• 而堆排序就只能下滤，如果忘了堆排序是怎么排的就gg了。