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: Wrong Answer

Solution code:
n = raw_input()
num = raw_input()
array = []
for line in num:
    if line != " ":
        array.append(line)
print array

for i in range(1, int(n)):
    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: Wrong Answer

Solution code:
n = raw_input()
num = raw_input()
array = []
for line in num:
    if line != " ":
        array.append(line)

for i in range(1, int(n)):
    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: Wrong Answer

Solution code:
n = raw_input()
num = raw_input()
array = []
for line in num:
    if line != " ":
        array.append(line)

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

Submission status: Wrong Answer

Solution code:
n = raw_input()
num = raw_input()
array = []
for line in num:
    if line != " ":
        array.append(line)

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: Wrong Answer

Solution code:
n = raw_input()
num = raw_input()
array = []
for line in num:
    if line != " ":
        array.append(line)
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: Wrong Answer

Solution code:
import sys

lines = sys.stdin.readlines()

N = lines[0]
A = lines[1].strip().split(" ")

print " ".join(A)

for i in range(1, len(A)):
    key = A[i]
    j = i - 1
    while True:
        if j >= 0 and A[j] > key:
            A[j+1] = A[j]
            j -= 1
        else:
            break
    A[j+1] = key
    print " ".join(A)

Submission status: Wrong Answer

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(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: Wrong Answer

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]:
    if i > 1:
      for j in 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: Wrong Answer

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]:
    if i > 1:
      for j in 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],
  print "\n"

Submission status: Wrong Answer

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(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],
  print "\n"

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = raw_input().split(" ")

print " ".join(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 = j - 1

    A[j+1] = v

    print " ".join(A)

Submission status: Wrong Answer

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]:
        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],
  print "\n"

Submission status: Wrong Answer

Solution code:
import sys

lines = sys.stdin.readlines()

N = lines[0]
A = lines[1].strip().split(" ")

print " ".join(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 -= 1
    A[j+1] = key
    print " ".join(A)

Submission status: Wrong Answer

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]:
        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],
  print "\n"

Submission status: Wrong Answer

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 = 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: Wrong Answer

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 = i
        for p in range(0, i):
          q = i - p
          x_list[q] = x_list[q - 1]
        x_list[j+1] = temp
      break
  for k in range(0, y):
    print x_list[k],
  print " "

Submission status: Wrong Answer

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
  for k in range(0, y):
    print x_list[k],
  print " "

Submission status: Wrong Answer

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: Wrong Answer

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 -= 1
    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: Wrong Answer

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 -= 1
    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: Wrong Answer

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 -= 1
    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: Wrong Answer

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: Wrong Answer

Solution code:
N = input()
a = raw_input()
print a
a = a.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
	for k in range(N):
		if k != N-1:
			print a[k],
		else:
			print a[k]

Submission status: Wrong Answer

Solution code:
N = input()
a = raw_input()
print a
a = a.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
	for k in range(N):
		if k != N-1:
			print a[k],
		else:
			print a[k]

Submission status: Wrong Answer

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

def insertion_sort(xs):
  for i in range(1, len(xs)):
    v = xs[i]
    j = i - 1
    while j >= 0 and xs[j] > v:
      xs[j + 1] = xs[j]
      j -= 1
    xs[j + 1] = v
    print(*xs)

insertion_sort(xs)

Submission status: Wrong Answer

Solution code:
import copy

def insertion_sort(List):
	l=len(List)
	for i in range(l):
		for j in range(i):
			if List[i]<List[j]:
				temp=copy.copy(List)
				for k in range(j,i):
					List[k+1]=temp[k]
				List[j]=temp[i]
				break
		print(List)

N=input()
N_List=map(int,raw_input().split())
insertion_sort(N_List)

Submission status: Wrong Answer

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

for i in range(n):

    if i == 0:
        continue

    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(' '.join([str(x) for x in l]))

Submission status: Wrong Answer

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

for i in range(n):

    if i == 0:
        continue

    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(*l)

Submission status: Wrong Answer

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

for i in range(n):

    if i == 0:
        continue

    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(*l)
    print(1)

Submission status: Wrong Answer

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

stdin_N = int(input())
stdin_A = input()
stdin_A = stdin_A.split(" ")
val = insertionSort(stdin_A, stdin_N)

Submission status: Wrong Answer

Solution code:
def insertionSort(a, n):
    for i in range(n):
        print(" ".join(str(s) for s in a))
        v = a[i]
        j = i - 1
        while j >= 0 and a[j] > v:
            a[j+1] = a[j]
            j -= 1
            a[j+1] = v

def main():
    n = int(input())
    a = list(map(int, input().split()))
    insertionSort(a, n)

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

def display(inp):
    s = len(inp)
    for i in range(s):
        if i!=len(inp)-1:
            print("%d" % inp[i], end=" ")
        else:
            print("%d" % inp[i], end="")
    print("")

line = sys.stdin.readline()
size = int(line)
line = sys.stdin.readline()
inp = []
for i in line.split(" "):
    inp.append(int(i))

display(inp)

for i in range(1,size):
    if inp[i]!=size:
        check = inp.pop(i)
        for j in range(len(inp)):
            if check<inp[j]:
                inp.insert(j,check)
                break
    display(inp)

Submission status: Wrong Answer

Solution code:
def insertionsSort(A):
    N = len(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)

N = int(input())
A = list(map(int, input().split()))
insertionsSort(A)

Submission status: Wrong Answer

Solution code:
n=int(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: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
print(a[0],a[1],a[2],a[3],a[4],a[5])
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[0],a[1],a[2],a[3],a[4],a[5])

Submission status: Wrong Answer

Solution code:
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(' '.join(map(str, A)))

if __name__ == "__main__":
    n = int(input())
    a = [int(e) for e in input().split()]
    insertionSort(a, n)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
def insertionSort(A, N):
    print " ".join(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 " ".join(A)

if __name__ == "__main__":
    N = input()
    A = raw_input().split()
    insertionSort(A, N)

Submission status: Wrong Answer

Solution code:
n = input()
data = [int(i) for i in input().split(' ')]

def insertion_sort(raw_list):
    for i, v in enumerate(raw_list):
       if i == 0:
           continue
       j = i - 1
       while j >= 0 and v < raw_list[j]:
           raw_list[j+1] = v 
           raw_list[j+1] = raw_list[j]
           j -= 1
       raw_list[j+1] = v 

    return raw_list

print(' '.join([str(i) for i in data]))
print(' '.join([str(i) for i in insertion_sort(data)]))

Submission status: Wrong Answer

Solution code:
n = input()
data = [int(i) for i in input().split(' ')]

def insertion_sort(raw_list):
    for i, v in enumerate(raw_list):
        if i == 0:
            continue
        j = i - 1
        while j >= 0 and v < raw_list[j]:
            raw_list[j+1] = v 
            raw_list[j+1] = raw_list[j]
            j -= 1
        raw_list[j+1] = v 
        print(' '.join([str(i) for i in raw_list]))

    return raw_list

print(' '.join([str(i) for i in data]))
print(' '.join([str(i) for i in insertion_sort(data)]))

Submission status: Wrong Answer

Solution code:
def insertionSort(a, n):
    for i in range(1, n):
        print a
        v = a[i]
        j = i - 1
        while j >= 0 and a[j] > v:
            a[j+1] = a[j]
            j -= 1
        a[j+1] = v
    else:
        print a

n = input()
a = map(int, raw_input().split())
insertionSort(a, n)

Submission status: Wrong Answer

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
 print(a)

Submission status: Wrong Answer

Solution code:
def insertionSort(At, Nt):
	for i in range(Nt):
		v = At[i]
		j = i - 1
		while j >= 0 and At[j] > v:
			A[j + 1] = A[j]
			j = j - 1
		A[j + 1] = v
		print(At)
	return At

N = int(input())
A = list(map(int, input().split()))
A = insertionSort(A, N)

Submission status: Wrong Answer

Solution code:
N = input()
l = map(int, raw_input().split())
i = 1
while i < N:
    print l
    tmp = l[i]
    j = i - 1
    while j >= 0 and tmp < l[j]:
        l[j + 1] = l[j]
        j -= 1
    l[j + 1] = tmp
    i += 1

Submission status: Wrong Answer

Solution code:
N = input()
l = map(int, raw_input().split())
i = 1
while i < N:
    print l
    tmp = l[i]
    j = i - 1
    while j >= 0 and tmp < l[j]:
        l[j + 1] = l[j]
        j -= 1
    l[j + 1] = tmp
    i += 1
print l

Submission status: Wrong Answer

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

def insertin_sort(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
        array_print(a)

def array_print(a):
    buf = ""
    for i in a:
        buf += str(i) + " "
    buf.rstrip()
    print buf
    

if __name__ == "__main__":
    n = int(raw_input())
    a = map(int, raw_input().split())
    insertin_sort(a, n)

Submission status: Wrong Answer

Solution code:
def insertionSort(A, n):
    for i in xrange(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 = input()
arr = map(int, raw_input().split())
print arr
insertionSort(arr, n)

Submission status: Wrong Answer

Solution code:
def insertionSort(A, n):
    for i in xrange(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

def printArray(A, n):
    for i in xrange(n):
        if i < n-1:
            print A[i],
        else:
            print A[i]

n = input()
arr = map(int, raw_input().split())
insertionSort(arr, n)
printArray(arr, n)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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 -= 1
    a[j + 1] = v
    print(' '.join(list(map(str, a))))

Submission status: Wrong Answer

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

def sort_print(n, input_list):
    # index[0]~ [n-1]?????§?¨??????????
    # ???????????????index??\???????????\?????°???????????°?????\????????????print???
    for i in range(n):
        index = i

        num = input_list[index]
        while index-1 >=0 and input_list[index-1] > num:
            input_list[index] = input_list[index-1]
            index -= 1
        input_list[index] = num

        print(input_list)

sort_print(n, input_list)

Submission status: Wrong Answer

Solution code:
def insert(array, index):
    value = array[index]
    for i in range(index-1, -1, -1):
        if array[i] < value:
            array[i] = value
            break
        array[i + 1] = array[i]
    else:
        array[0] = value

def insertion_sort(array, log=False):
    for i in range(len(array)):
        insert(array, i)
        if log:
            print(*array)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    insertion_sort(A, True)

Submission status: Wrong Answer

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-=1
    a[j+1]=v
    print(a)

Submission status: Wrong Answer

Solution code:
N = int(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: Wrong Answer

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-=1
    a[j+1]=v
    print(*a)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(x) for x in 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: Wrong Answer

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
for i in range(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: Wrong Answer

Solution code:
#coding: utf-8
#ALDS1_1A
import sys

n=int(raw_input())
a=map(int,raw_input().split())

for i in xrange(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 k in xrange(n):
  print a[k],
 print

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
cnt = 0
def insertionSort(A,n,g):
	global cnt
	for i in range(g,n):
		v = A[i]
		j = i - g
		while j >= 0 and A[j] > v:
			A[j+g] = A[j]
			j = j - g
			cnt += 1
		A[j+g] = v
	return A
def shellSort(A,n):
	m = 2
	G = [4,1]
	for x in G:
		A=insertionSort(A,n,x)
	print(m)
	print(*G)
	print(cnt)
	print("\n".join(map(str, A)))
shellSort(a,N)

Submission status: Wrong Answer

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

for i in range(n):
    key = l[i]
    j = i -1
    while j >= 0 and l[j] > key:
        l[j + 1] = l[j]
        j = j - 1
    l[j + 1] = key
    print(l)

Submission status: Wrong Answer

Solution code:
import string
n = int(input())
l = []
l = input().split()
for i in range(n):
    key = l[i]
    j = i -1
    while j >= 0 and l[j] > key:
        l[j + 1] = l[j]
        j = j - 1
    l[j + 1] = key
    print(' '.join(l))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import string
n = int(input())
l = []
l = input().split()
for i in range(n):
    key = l[i]
    j = i -1
    while j >= 0 and l[j] > key:
        l[j + 1] = l[j]
        j -= 1
    l[j + 1] = key
    print(' '.join(l))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def Sort(N,List):
    for i in range(1,N):
        v = List[i]
        j = i - 1
        while j >= 0 and List[j] > v:
            List[j+1] = List[j]
            j -= 1
        List[j+1] = v
        print List

if __name__ == "__main__":
    N = int(raw_input())
    List = map(int,raw_input().split(' '))
    Sort(N,List)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
List = map(int,raw_input().split(' '))
def Sort(N,List):
    for i in range(1,N):
        v = List[i]
        j = i - 1
        while j >= 0 and List[j] > v:
            List[j+1] = List[j]
            j -= 1
        List[j+1] = v
        print ' '.join(map(str, List))
Sort(N,List)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = input()
A = 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: Wrong Answer

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: Wrong Answer

Solution code:
N = input()
A = map(int, raw_input().split())
for i in range(1,N):
    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: Wrong Answer

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


def insertion_sort(A):
    for i in xrange(1, N, 1):
        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 ' '.join(map(str, A))
    return A


if __name__ == "__main__":
    N = input()
    A = map(int, raw_input().split())
    result = insertion_sort(A)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import sys


def main():
  args = input()
  print(args)
  length = 6
  elements = "1 2 3 4 5 6".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: Wrong Answer

Solution code:
#!/usr/bin/python

import sys


def main():
  args = input()
  print(args)
  length = 6
  elements = "5 2 4 6 1 3".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: Wrong Answer

Solution code:
#!/usr/bin/python

import sys


def main():
  length = int(input())
  elements = list(map(int, 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: Wrong Answer

Solution code:
n = int(input())
A = 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(" ".join(A))

Submission status: Wrong Answer

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

import sys

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
    sys.stdout.write(" ".join(A))
    if i < n - 1:
        sys.stdout.write("\n")

Submission status: Wrong Answer

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

print(" ".join(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(" ".join(A))

Submission status: Wrong Answer

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

def insertionSort(A, N):
    for i in range(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)

insertionSort(A, N)

Submission status: Wrong Answer

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

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