Problem:


Insertion Sort

Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:

for i = 1 to A.length-1
    key = A[i]
    /* insert A[i] into the sorted sequence A[0,...,j-1] */
    j = i - 1
    while j >= 0 and A[j] > key
        A[j+1] = A[j]
        j--
    A[j+1] = key

Note that, indices for array elements are based on 0-origin.

To illustrate the algorithms, your program should trace intermediate result for each step.

Input

The first line of the input includes an integer N, the number of elements in the sequence.

In the second line, N elements of the sequence are given separated by a single space.

Output

The output consists of N lines. Please output the intermediate sequence in a line for each step. Elements of the sequence should be separated by single space.

Constraints

1 ≤ N ≤ 100

Sample Input 1

6
5 2 4 6 1 3

Sample Output 1

5 2 4 6 1 3
2 5 4 6 1 3
2 4 5 6 1 3
2 4 5 6 1 3
1 2 4 5 6 3
1 2 3 4 5 6

Sample Input 2

3
1 2 3

Sample Output 2

1 2 3
1 2 3
1 2 3

Hint

Template in C



Sample input:
6
5 2 4 6 1 3


Sample output:
5 2 4 6 1 3
2 5 4 6 1 3
2 4 5 6 1 3
2 4 5 6 1 3
1 2 4 5 6 3
1 2 3 4 5 6

Submission status: Runtime Error

Solution code:
*
 * Created by heads on 8/24/2018.
 */
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
// Get numbers
        int n = input.nextInt();
        int[] nums = new int[n];

// fill array
        for(int i = 0; i < n; i++){
            nums[i] = input.nextInt();
        }

        insertSort(n, nums);
    }

    public static void insertSort(int n, int[] nums){
        for(int i = 1; i<= nums.length-1; i++){
            printHelp(nums);
            int key = nums[i];
            // insert A[i] into the sorted sequence A[0,...,j-1]
            int j = i - 1;
            while(j >= 0 && nums[j] > key){
                nums[j+1] = nums[j];
                j--;
            }
            nums[j+1] = key;
        }
        printHelp(nums);
    }

    private static void printHelp(int[] nums){
        for(int i : nums){
            System.out.print(i + " ");
        }
        System.out.print("\n");
    }
}

Submission status: Runtime Error

Solution code:
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
// Get numbers
        int n = input.nextInt();
        int[] nums = new int[n];

// fill array
        for(int i = 0; i < n; i++){
            nums[i] = input.nextInt();
        }

        insertSort(n, nums);
    }

    public static void insertSort(int n, int[] nums){
        for(int i = 1; i<= nums.length-1; i++){
            printHelp(nums);
            int key = nums[i];
            // insert A[i] into the sorted sequence A[0,...,j-1]
            int j = i - 1;
            while(j >= 0 && nums[j] > key){
                nums[j+1] = nums[j];
                j--;
            }
            nums[j+1] = key;
        }
        printHelp(nums);
    }

    private static void printHelp(int[] nums){
        for(int i : nums){
            System.out.print(i + " ");
        }
        System.out.print("\n");
    }
}

Submission status: Runtime Error

Solution code:
# inputList = list(map(int, '''6
# 5 2 4 6 1 3'''.split()))

inputList = list(map(int, input.split()))


def insertionSort(A, N):
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]

            j-=1
        A[j+1] = v
        print(A)

N = int(inputList.pop(0))

print(inputList)
insertionSort(inputList, N)

Submission status: Runtime Error

Solution code:
# inputList = list(map(int, '''6
# 5 2 4 6 1 3'''.split()))
# N = inputList.pop(0)

N = input()

inputList = list(map(int, input.split()))

def formatting(nums):
    for i in range(len(nums)):
        if i != len(nums) - 1:
            print(nums[i],end=' ')
        else:
            print(nums[i])


def insertionSort(A, N):
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]

            j-=1
        A[j+1] = v
        formatting(A)

formatting(inputList)
insertionSort(inputList, N)

Submission status: Runtime Error

Solution code:
input()
myarr = list(map(int, split(input())))
for i in range(1, len(myarr)):
    for j in range(i, 0,-1):
        if myarr[j] < myarr[j-1]:
            t = myarr[j]
            myarr[j] = myarr[j-1]
            myarr[j-1] = t
        else:
            break
    print(" ".join(map(str, myarr)))

Submission status: Runtime Error

Solution code:
input()
myarr = list(map(int, input().split())
for i in range(1, len(myarr)):
    for j in range(i, 0,-1):
        if myarr[j] < myarr[j-1]:
            t = myarr[j]
            myarr[j] = myarr[j-1]
            myarr[j-1] = t
        else:
            break
    print(" ".join(map(str, myarr)))

Submission status: Runtime Error

Solution code:
def insertion_sort(arr):
    for i in range(1,len(arr)):
        j = i
        while arr[j] < arr[j-1] and j > 0:
            arr[j-1], arr[j] = arr[j], arr[j-1]
            j -= 1
        print(" ".join(arr))

input()
arr = list(map(int, input().split()))
insertion_sort(arr)

Submission status: Runtime Error

Solution code:
def inserrtionsort(l,n):
  for i in range(1,n):
    v=l[i]
    j=i-1
    while v<l[j] and j>=0:
      l[j+1]=l[j]
      j-=1
    l[j+1]=v
    print(""join(l))
  print("".join(l))
n=list(input())
m=int(input())
inserrtionsort(m,n)

Submission status: Runtime Error

Solution code:
def inserrtionsort(l,n):
  for i in range(1,n):
    print(" ".join(l))
    v=l[i]
    j=i-1
    while v<l[j] and j>=0:
      l[j+1]=l[j]
      j-=1
    l[j+1]=v
  print(" ".join(l))
m=int(input())
n=list(map(int,input().split()))
inserrtionsort(n,m)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input()))
def insertionSort(a, n):#配列aを挿入ソートで並び替える(昇順）
    for i in range(1,n-1):
        v = a[i]
        j = i - 1
        while  >= 0 and a[j] > v:
            a[j+1] = a[j]#a[i]の位置に詰めていく処理
            j -= 1
            print(" ".join(a))#１行ごとに出力
        a[j+1] = v

insertionSort(l,n)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input.split()))

for i in range(1,N):
    v = A[i]
    j = i-1
    while(j >= 0 and A[j] > v):
        A[j+1] == A[j]
        j -= j
    A[j+1] = v

Submission status: Runtime Error

Solution code:
def show(nums):
    for i in range(len(nums)):
        if i !=len(nums)-1:
            print(nums[i],end='')
        else:
            print(nums[i])

n=int(input())
nums=list(map(int,input().split()))
show(nums)
for i in range(1,n):
    v=nums[i]
    j=i-1
    while (j>=0 and nus[j]>v):
        nums[j+1]=nums[j]
        j--
    nums[j+1] = v
    shows(nums)

Submission status: Runtime Error

Solution code:
def show(nums):
    for i in range(len(nums)):
        if i !=len(nums)-1:
            print(nums[i],end='')
        else:
            print(nums[i])

n=int(input())
nums=list(map(int,input().split()))
show(nums)
for i in range(1,n):
    v=nums[i]
    j=i-1
    while (j>=0 and nus[j]>v):
        nums[j+1]=nums[j]
        j -= 1
    nums[j+1] = v
    shows(nums)

Submission status: Runtime Error

Solution code:
def show(nums):
    for i in range(len(nums)):
        if i !=len(nums)-1:
            print(nums[i],end=' ')
        else:
            print(nums[i])

n=int(input())
nums=list(map(int,input().split()))
show(nums)
for i in range(1,n):
    v=nums[i]
    j=i-1
    while (j>=0 and nus[j]>v):
        nums[j+1]=nums[j]
        j -= 1
    nums[j+1] = v
    shows(nums)

Submission status: Runtime Error

Solution code:
def show(nums):
    for i in range(len(nums)):
        if i !=len(nums)-1:
            print(nums[i],end=' ')
        else:
            print(nums[i])

n=int(input())
nums=list(map(int,input().split()))
show(nums)
for i in range(1,n):
    v=nums[i]
    j=i-1
    while (j>=0 and nums[j]>v):
        nums[j+1]=nums[j]
        j -= 1
    nums[j+1] = v
    shows(nums)

Submission status: Runtime Error

Solution code:
n = int(input())
nums = list(map(int, input().split(' ')))

for i in range(len(nums)):
    key = nums[i]
    j = i - 1
    while j >= 0 and nums[j] > key:
        nums[j+1] = nums[j]
        j -= 1
    nums[j+1] = key
    print(' '.join(map(str, nums)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
def insertSort(array):
    for i in array[1:]:
        [print(array[i]) for i in array]
        v = array[i]
        j = i - 1
        while j >= 0 and array[j] > v:
            array[j+1] = array[j]
            j -= 1
        array[j+1] = v
        
if __name__ == '__main__':
    n = input()
    index = [int for i in input().split()]
    insertSort(index)

Submission status: Runtime Error

Solution code:
n = int(raw_input())
arr = map(int, raw_input().split(' '))

p = 1
print ' '.join(map(str, arr))
while True:
    for j in range(0,p):
        if arr[p] < arr[j]:
            arr[p],arr[j] = arr[j],arr[p]
    p += 1
    print ' '.join(map(str, arr))
    if p >= len(arr):
        break

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))

for i in range(1,n):
	print(" ".join(map(int,A)))
	j=i-1
	while A[j]<A[j-1] and j>0:
		(A[j],A[j-1])=(A[j-1],A[j])
		j=j-1
else:
	print(" ".join(map(int,A)))

Submission status: Runtime Error

Solution code:
num = raw_input()
num_list = raw_input()
num_list = num_list.split()
print "???".join(num_list)
 
for i in range(1, len(num_list)):
        temp = num_list[i]
        j = i - 1
        while (j >= 0 and num_list[j] > temp):
                num_list[j+1] = num_list[j]
                j -= 1
        num_list[j+1] = temp
        print "???".join(num_list)

Submission status: Runtime Error

Solution code:
num = int(raw_input())
line = raw_input()

A_str = line.strip().split(" ")
print " ".join(A_str)
A = map(int, item_str)

for i in range(1, num):
    v = A[i]
    j = i - 1
    for j in range(j, -1, -1):
        if A[j] > v:
            A[j+1] = A[j]
            j -= 1
        else:
            break
    A[j+1] = v
    A_str = map(str, A)
    print " ".join(A_str)

Submission status: Runtime Error

Solution code:
a=[]
n=int(input())
s=input()
a=list(map(int,s.split()))
insertionSort(a,n)

def insertionSort(a,n):
    for i in range(n):
        print(a[i],end="")
        if(i!=n-1):
            print(" ",end="")
    print("")    
    for i in range(1,n):
        v=a[i]
        j=i-1
        while(j>=0 and a[j]>v):
            a[j+1] = a[j]
            j-=1
        a[j+1] = v
        for i in range(n):
            print(a[i],end="")
            if(i!=n-1):
                print(" ",end="")
        print("")

Submission status: Runtime Error

Solution code:
import sys

y = sys.stdin.readline()
y = int(y)

x = sys.stdin.readline()

x_list = int(x.split(" "))

for i in range(1, y):
  if i > 0:
    j = i - 1
    if list(i) < list(j):
      list(i),  list(j) = list(j), list(i)
      i = i - 2

Submission status: Runtime Error

Solution code:
import sys

y = sys.stdin.readline()
y = int(y)

x = sys.stdin.readline()

x_list = int(x.split(" "))

for i in range(1, y + 1):
  if list(i) < list(i - 1):
    for j range(i - 1, 0):
      if list(j) < list(i):
        list(i),  list(j+1) = list(j+1), list(i)
        break
  for k in range(0, y):
    print list(j)

Submission status: Runtime Error

Solution code:
import sys

y = sys.stdin.readline()
y = int(y)

x = sys.stdin.readline()

x_list = int(x.split(" "))

for i in range(1, y + 1):
  if list(i) < list(i - 1):
    for j range(i - 1, 0):
      if list(j) < list(i):
        list(i),  list(j+1) = list(j+1), list(i)
        break
  for k in range(0, y):
    print list(k)

Submission status: Runtime Error

Solution code:
import sys

y = sys.stdin.readline()
y = int(y)

x = sys.stdin.readline()

x_list = int(x.split(" "))

for i in range(1, y):
  if list(i) < list(i - 1):
    for j range(i - 1, -1):
      if list(j) < list(i):
        list(i),  list(j+1) = list(j+1), list(i)
        break
  for k in range(0, y):
    print list(k)

Submission status: Runtime Error

Solution code:
import sys

y = sys.stdin.readline()
y = int(y)

x = sys.stdin.readline()

x_list = int(x.split(" "))

for i in range(1, y):
  if x_list[i] < x_list[i - 1]:
    for j range(i - 1, -1):
      if x_list[j] < x_list[i]:
        x_list[i],  x_list[j+1] = x_list[j+1], x_list[i]
        break
  for k in range(0, y):
    print x_list[k]

Submission status: Runtime Error

Solution code:
import sys

y = sys.stdin.readline()
y = int(y)

x = sys.stdin.readline()

x_list = x.split(" ")

for i in range(y):
  x_list[i] = int(x_list[i])

for i in range(1, y):
  if x_list[i] < x_list[i - 1]:
    for j in range(0, i - 1):
      if x_list[j] > x_list[i]:
        temp = x_list[i]
        for p in range(0, i):
          q = i - p
          x_list[q] = x_list[q - 1]
        x_list[j+1] = temp
      elif x_list[0] > x_list[i]
        for p in range(0, i):
          q = i - p
          temp = x_list[i]
          x_list[q] = x_list[q - 1]
        x_list[0] = temp
  for k in range(0, y):
    print x_list[k],
  print " "

Submission status: Runtime Error

Solution code:
import sys

y = sys.stdin.readline()
y = int(y)

x = sys.stdin.readline()

x_list = x.split(" ")

for i in range(y):
  x_list[i] = int(x_list[i])

for i in range(1, y):
  if x_list[i] < x_list[i - 1]:
    for j in range(0, i - 1):
      
      if x_list[0] > x_list[i]
        for p in range(0, i):
          q = i - p
          temp = x_list[i]
          x_list[q] = x_list[q - 1]
        x_list[0] = temp
      elif x_list[j] > x_list[i]:
        temp = x_list[i]
        for p in range(0, i):
          q = i - p
          x_list[q] = x_list[q - 1]
        x_list[j+1] = temp
  for k in range(0, y):
    print x_list[k],
  print " "

Submission status: Runtime Error

Solution code:
import sys

def inserttionSort(x_list,y):
  for i in range(1, y):
    v = x_list[i]
    j = i - 1
    while j >= 0 and x_list[j] > v:
      x_list[j + 1] = x_list[j]
      j--
    x_list[j+1] = v
  for k in range(0, y):
    print x_list[k],
  print " "



y = sys.stdin.readline()
y = int(y)

x = sys.stdin.readline()

x_list = x.split(" ")

for i in range(y):
  x_list[i] = int(x_list[i])

for i in range(1, y):

Submission status: Runtime Error

Solution code:
import sys

def insertionSort(x_list,y):
  for i in range(1, y):
    v = x_list[i]
    j = i - 1
    while j >= 0 and x_list[j] > v:
      x_list[j + 1] = x_list[j]
      j--
    x_list[j+1] = v
  for k in range(0, y):
    print x_list[k],
  print " "



y = sys.stdin.readline()
y = int(y)

x = sys.stdin.readline()

x_list = x.split(" ")

for i in range(y):
  x_list[i] = int(x_list[i])

insertionSort(x_list, y)

Submission status: Runtime Error

Solution code:
n = raw_input()
num = raw_input()
array = []
array = num.strip().split(" ")

for i in range(1, int(n)):
    print " ".join(array)
    v = array[i]
    j = i - 1
    while j >= 0 and array[j] > v:
        array[j + 1] = array[j]
        j -= 1
    array[j + 1] = v
print " ".join(array

Submission status: Runtime Error

Solution code:
import sys

def insertionSort(A, N):
    for n in range(N-1):
        print (A[n], end=" ")
    print(A[N-1])
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j = j - 1
        A[j + 1] = v
        
        for n in range(N-1):
            print (A[n], end=" ")
        print(A[N-1])
    return A

N = int(input())
A = input()
A = A.split(" ")
for i in range(N):
    A[i] = int(A[i])
val = insertionSort(stdin_A, stdin_N)

Submission status: Runtime Error

Solution code:
def main():
    N = input()
    a = map(int, raw_input().split())
    print ' '.join(map(str,a))
    for i in xrange(1,len(a)-1):
        v = a[i]
        j = i - 1
        while j >= 0 && a[j] > v:
            a[j+1] = a[j]
            j -= 1
        a[j+1] = v
        print ' '.join(map(str,a))
    return 0

main()

Submission status: Runtime Error

Solution code:
q=input()
a=map(int,rar_input().split())
for i in range(q):
 k=a[i]
 j=i-1
 while j>=0 and a[j]>key:
  a[j+1]=a[j]
  j-=1
 a[j+1]=key
 print(a)

Submission status: Runtime Error

Solution code:
q=input()
a=map(int,raw_input().split())
for i in range(q):
 k=a[i]
 j=i-1
 while j>=0 and a[j]>key:
  a[j+1]=a[j]
  j-=1
 a[j+1]=key
 print(a)

Submission status: Runtime Error

Solution code:
q=input()
a=map(int,raw_input().split())
for i in range(q):
 k=a[i]
 j=i-1
 while j>=0 and a[j]>k:
  a[j+1]=a[j]
  j-=1
 a[j+1]=k
 text=""
 for I in a:
  text=text+' '+I
 print(text)

Submission status: Runtime Error

Solution code:
q=input()
a=map(int,raw_input().split())
for i in range(q):
 k=a[i]
 j=i-1
 while j>=0 and a[j]>k:
  a[j+1]=a[j]
  j-=1
 a[j+1]=k
 text=str()
 for I in a:
  text=text+' '+str(I)
 print(text)

Submission status: Runtime Error

Solution code:
n = int(input())
l = [int(x) for x in input().split()]

for i in range(n):
    a = l[i]
    j = i - 1

    while j >= 0 and l[j] > a:
        l[j+1] = l[j]
        j = j - 1

    l[j + 1] = a
    print(*1)

Submission status: Runtime Error

Solution code:
N = input()
a=map(int,raw_input().split())
print(a)
for i in range(1,N):
    v = a[i]
    j = i-1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j-=1
    a[j+1]=v
    print(a)

Submission status: Runtime Error

Solution code:
N = input()
a=map(int,raw_input().split())
print(a)
for i in range(1,N):
    v = a[i]
    j = i-1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j-=1
    a[j+1]=v
    print(a)
return

Submission status: Runtime Error

Solution code:
N = input()
a=list(map(int,raw_input().split()))
print(a)
for i in range(1,N):
    v = a[i]
    j = i-1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j-=1
    a[j+1]=v
    print(a)

Submission status: Runtime Error

Solution code:
N = input()
a=list(map(int,input().split()))
print(a)
for i in range(1,N):
    v = a[i]
    j = i-1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j-=1
    a[j+1]=v
    print(a)

Submission status: Runtime Error

Solution code:
N = input()
a=list(map(int,raw_input().split()))
for i in range(1,N):
    v = a[i]
    j = i-1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j-=1
    a[j+1]=v
    print(*a)

Submission status: Runtime Error

Solution code:
#?????????
N = input()
A = map(int, raw_input().split())
for i in range(len(A)):
    v = A[i]
    j = i - 1
    while (j >= 0) & (A[j] > v):
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print ' '.join(map(str, A))

Submission status: Runtime Error

Solution code:
#!/usr/bin/python

import sys


def main():
  length, elements = sys.argv[1].split('\n')
  length = int(length)
  elements = elements.split()
  print(" ".join(elements))
  elements = [str(i) for i in elements]

  sorted_list = [elements[0]]
  for i in range(1, length):
    element = elements[i]
    for j in range(0, len(sorted_list) + 1):
      if j == len(sorted_list):
        sorted_list.append(element)
        break
      elif element < sorted_list[j]:
        sorted_list.insert(j, element)
        break
    output_list = sorted_list[0:i+1] + elements[i+1:]
    print(" ".join([str(i) for i in output_list]))


if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/python

import sys


def main():
  length, elements = sys.argv[1].split('\n')
  length = int(length)
  elements = elements.split()
  print(" ".join(elements))
  elements = [str(i) for i in elements]

  sorted_list = [elements[0]]
  for i in range(1, length):
    element = elements[i]
    for j in range(0, len(sorted_list) + 1):
      if j == len(sorted_list):
        sorted_list.append(element)
        break
      elif element < sorted_list[j]:
        sorted_list.insert(j, element)
        break
    output_list = sorted_list[0:i+1] + elements[i+1:]
    print(" ".join([str(i) for i in output_list]))

    return 0

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/python

import sys


def main():
  args = input()
  length = args[0]
  elements = args[1].split()
  print(" ".join(elements))
  elements = [str(i) for i in elements]

  sorted_list = [elements[0]]
  for i in range(1, length):
    element = elements[i]
    for j in range(0, len(sorted_list) + 1):
      if j == len(sorted_list):
        sorted_list.append(element)
        break
      elif element < sorted_list[j]:
        sorted_list.insert(j, element)
        break
    output_list = sorted_list[0:i+1] + elements[i+1:]
    print(" ".join([str(i) for i in output_list]))

    return 0

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/python

import sys


def main():
  args = input()
  print(args)
  length = 6
  elements = [5, 2, 4, 6, 1, 3]
  print(" ".join(elements))
  elements = [str(i) for i in elements]

  sorted_list = [elements[0]]
  for i in range(1, length):
    element = elements[i]
    for j in range(0, len(sorted_list) + 1):
      if j == len(sorted_list):
        sorted_list.append(element)
        break
      elif element < sorted_list[j]:
        sorted_list.insert(j, element)
        break
    output_list = sorted_list[0:i+1] + elements[i+1:]
    print(" ".join([str(i) for i in output_list]))

    return 0

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/python

import sys


def main():
  args = input()
  a = []
  for arg in args:
    a.append(arg)
  length = a[0]
  elements = a[1]
  print(" ".join(elements))
  elements = [str(i) for i in elements]

  sorted_list = [elements[0]]
  for i in range(1, length):
    element = elements[i]
    for j in range(0, len(sorted_list) + 1):
      if j == len(sorted_list):
        sorted_list.append(element)
        break
      elif element < sorted_list[j]:
        sorted_list.insert(j, element)
        break
    output_list = sorted_list[0:i+1] + elements[i+1:]
    print(" ".join([str(i) for i in output_list]))

    return 0

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/python

import sys


def main():
  length = int(raw_input())
  elements = map(int, raw_input().split())
  print(" ".join(str(i) for i in elements))

  sorted_list = [elements[0]]
  for i in range(1, length):
    element = elements[i]
    for j in range(0, len(sorted_list) + 1):
      if j == len(sorted_list):
        sorted_list.append(element)
        break
      elif element < sorted_list[j]:
        sorted_list.insert(j, element)
        break
    output_list = sorted_list[0:i+1] + elements[i+1:]
    print(" ".join([str(i) for i in output_list]))

    return 0

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/python

import sys


def main():
  length = int(raw_input())
  elements = list(map(int, raw_input().split()))
  print(" ".join(str(i) for i in elements))

  sorted_list = [elements[0]]
  for i in range(1, length):
    element = elements[i]
    for j in range(0, len(sorted_list) + 1):
      if j == len(sorted_list):
        sorted_list.append(element)
        break
      elif element < sorted_list[j]:
        sorted_list.insert(j, element)
        break
    output_list = sorted_list[0:i+1] + elements[i+1:]
    print(" ".join([str(i) for i in output_list]))

    return 0

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
n = int(input())
A = input().split(' ')

for i in range(1, n-1):
    v = A[i]
    j = i - 1
    while j >= 0 && A[j] > v:
        A[j+1] = A[j]
        j--
        A[j+1] = v
    print(" ".join(A))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-


def insertion_sort(n, A):
    for i in xrange(1, len(A)):
        key = A[i]
        j = i - 1
        while j >= 0 and A[j] > key:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = key

if __name__ == "__main__":
    n = int(raw_input())
    A = raw_input().split(" ")
    A = map(int, A)
    insertion_sort(n, A)
    print " ".join(A).strip()

Submission status: Runtime Error

Solution code:
A = input().split()
N = A.pop()
# print(N)
# print(A)
 
# A = [5, 2, 4, 6, 1, 3]
print(' '.join(map(str, A)))
for i in range(1, len(A)):
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j+1] = A[j]
        j = j - 1
    A[j+1] = key
    print(' '.join(map(str, A)))

Submission status: Runtime Error

Solution code:
print(' '.join([str(item) for item in A])

for i in range(1, len(A)):
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j+1] = A[j]
        j = j - 1
    A[j+1] = key
    print(' '.join(map(str, A)))

Submission status: Runtime Error

Solution code:
A = [int(item) for item in input().split()]
N = A.pop()

print(' '.join([str(item) for item in A]))
for i in range(1, N):
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j+1] = A[j]
        j = j - 1
    A[j+1] = key
    print(' '.join([str(item) for item in A]))

Submission status: Runtime Error

Solution code:
A = [int(item) for item in input().split()]
N = A.pop(0)

print(' '.join([str(item) for item in A]))
for i in range(1, N):
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j+1] = A[j]
        j = j - 1
    A[j+1] = key
    print(' '.join([str(item) for item in A]))

Submission status: Runtime Error

Solution code:
input = input().split()
A = [int(item) for item in input]
N = A.pop(0)

print(' '.join([str(item) for item in A]))
for i in range(1, N):
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j+1] = A[j]
        j = j - 1
    A[j+1] = key
    print(' '.join([str(item) for item in A]))

Submission status: Runtime Error

Solution code:
x = input().split()
A = [int(item) for item in x]
N = A.pop(0)

print(' '.join([str(item) for item in A]))
for i in range(1, N):
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j+1] = A[j]
        j = j - 1
    A[j+1] = key
    print(' '.join([str(item) for item in A]))

Submission status: Runtime Error

Solution code:
A = [5, 2, 4, 6, 1, 3]

print(' '.join([str(item) for item in A]))
for i in range(1, N):
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j+1] = A[j]
        j = j - 1
    A[j+1] = key
    print(' '.join([str(item) for item in A]))

Submission status: Runtime Error

Solution code:
_ = input()
A = [int(i) for i in input().split(" ")]
for i in range(1, len(A)):
  print(" ".join(A))
  key = A[i]
  j = i - 1
  while j >= 0 and A[j] > key:
    A[j + 1] = A[j]
    j -= 1
  A[j] = key

Submission status: Runtime Error

Solution code:
_ = input()
A = [int(i) for i in input().split(" ")]
for i in range(1, len(A)):
  print(" ".join(A))
  key = A[i]
  j = i - 1
  while j >= 0 and A[j] > key:
    A[j + 1] = A[j]
    j -= 1
  A[j + 1] = key

Submission status: Runtime Error

Solution code:
def insertionSort(_list, _length):
    for i in range(1, _length):
        ll = [str(_l) for _l in _list]
        print(' '.join(ll))
        val = _list[i]
        j = i - 1
        while j >= 0 and _list[j] > val:
            _list[j+1] = _list[j]
            j -= 1
        _list[j+1] = val
    ll = [str(_l) for _l in _list]
    print(' '.join(ll))


import sys
 
length = input()
eles = map(int, sys.stdin.readlines())

insertionSort(eles, length)

Submission status: Runtime Error

Solution code:
def insertionSort(_list, _length):
    for i in range(1, _length):
        ll = [str(_l) for _l in _list]
        print(' '.join(ll))
        val = _list[i]
        j = i - 1
        while j >= 0 and _list[j] > val:
            _list[j+1] = _list[j]
            j -= 1
        _list[j+1] = val
    ll = [str(_l) for _l in _list]
    print(' '.join(ll))


import sys
 
length = input()
eles = map(int, sys.stdin.readlines().rstrip().split(' '))

insertionSort(eles, length)

Submission status: Runtime Error

Solution code:
import sys
 
length = input()
eles = map(int, sys.stdin.readlines().rstrip().split(' '))

print(eles)

Submission status: Runtime Error

Solution code:
def insertionSort(_list, _length):
    for i in range(1, _length):
        ll = [str(_l) for _l in _list]
        print(' '.join(ll))
        val = _list[i]
        j = i - 1
        while j >= 0 and _list[j] > val:
            _list[j+1] = _list[j]
            j -= 1
        _list[j+1] = val
    ll = [str(_l) for _l in _list]
    print(' '.join(ll))

length = input()
eles = [ele for ele in input().rstrip().split(' ')]

insertionSort(eles, length)

Submission status: Runtime Error

Solution code:
length = int(input())
eles = list(map(int, input().split()))

for i in range(_length):
    val = _list[i]
    j = i - 1
    while j >= 0 and _list[j] > val:
        _list[j+1] = _list[j]
        j -= 1
    _list[j+1] = val
    print(*_list)

Submission status: Runtime Error

Solution code:
n= int(input())
l= list(map(int,input().split()))

s= ''
	for k in l:
		s+=' '+str(k)
	print(s)
	
for m in range(n-1):
	j=m+1
	if(l[j-1]>l[j]):
		i=j
		while(not i==0):
			if(not(l[i-1]<l[i])):
				l[i-1],l[i]= l[i],l[i-1]
				i-=1
			else:
				break
	s= ''
	for k in l:
		s+=' '+str(k)
	print(s)

Submission status: Runtime Error

Solution code:
N = input()
n = list(map(int,input().split()))
for i in range(1,int(N)):
    v = n[i]
    j = i - 1
    while j >= 0 and v < n[j]:
        n[j+1] = n[j]
        j = j - 1
    n[j+1] = v
    print(n)

Submission status: Runtime Error

Solution code:
N = input()
n = list(map(int,raw_input().split()))

for i in range(1,int(N)):
    v = n[i]
    j = i - 1
    while j >= 0 and v < n[j]:
        n[j+1] = n[j]
        j = j - 1
    n[j+1] = v
    print(n.replace("[","").replace(",","").replace("]","")))

Submission status: Runtime Error

Solution code:
N = input()
n = list(map(int,raw_input().split()))

for i in range(1,int(N)):
    v = n[i]
    j = i - 1
    while j >= 0 and v < n[j]:
        n[j+1] = n[j]
        j = j - 1
    n[j+1] = v
    print(n.replace("[","").replace(",","").replace("]",""))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# encoding: utf-8

from __future__ import print_function


class Solution:
    """
    @param prices: Given an integer array
    @return: Maximum profit
    """

    @staticmethod
    def insertion_sort():
        # write your code here
        array_length = raw_input()
        unsorted_array = list(map(int, raw_input().split()))

        for i in range(1, array_length):
            v = unsorted_array[i]
            j = i - 1
            while j >= 0 and unsorted_array[j] > v:
                unsorted_array[j + 1] = unsorted_array[j]
                j -= 1
            unsorted_array[j + 1] = v
            print(" ".join(str(i) for i in unsorted_array))


if __name__ == '__main__':
    solution = Solution()
    solution.insertion_sort()

Submission status: Runtime Error

Solution code:
array_length = raw_input()
unsorted_array = list(map(int, raw_input().split()))

for i in range(1, array_length):
    v = unsorted_array[i]
    j = i - 1
    while j >= 0 and unsorted_array[j] > v:
        unsorted_array[j + 1] = unsorted_array[j]
        j -= 1
    unsorted_array[j + 1] = v
    print(" ".join(str(i) for i in unsorted_array))

Submission status: Runtime Error

Solution code:
array_length = raw_input()
unsorted_array = list(map(int, raw_input().split()))

for i in range(array_length):
    v = unsorted_array[i]
    j = i - 1
    while j >= 0 and unsorted_array[j] > v:
        unsorted_array[j + 1] = unsorted_array[j]
        j -= 1
    unsorted_array[j + 1] = v
    print(" ".join(str(i) for i in unsorted_array))