def print_list(array, N):
    for i in range(N):
        if i == N-1:
            print(array[i])
        else:
            print(array[i], end=" ")
            
def stable_sort(array_a, array, N):
    for i in range(N-1):
        stable = "yes"
        if array[i][1] == array[i+1][1]:
            index_1 = array.index(array[i])
            index_2 = array.index(array[i+1])
            index_a1 = array_a.index(array[i])
            index_a2 = array_a.index(array[i+1])
            #print(index_1, index_2, index_a1, index_a2)
            if not(index_1 < index_2\
            and index_a1 < index_a2):
                stable = "no"
                break
    if stable == "yes":
        print("Stable")
    else:
        print("Not stable")
            
N = int(input())
a = input().split()
b = [s for s in a]
for i in range(N-1):
    for j in range(N-1, i, -1):
        if b[j][1] < b[j-1][1]:
            t = b[j]
            b[j] = b[j-1]
            b[j-1] = t
print_list(b, N)
stable_sort(a, b, N)

c = [s for s in a]
for i in range(N-1):
    min_i = c[i][1]
    change = "no"
    for j in range(i+1, N):
        if min_i > c[j][1]:
            min_i = c[j][1]
            index = c.index(c[j])
            change = "ok"
    if change == "ok":
        t = c[i]
        c[i] = c[index]
        c[index] = t
print_list(c, N)
stable_sort(a, c, N) def print_list(array, N):
    for i in range(N):
        if i == N-1:
            print(array[i])
        else:
            print(array[i], end=" ")
             print_list for i in range(N):
        if i == N-1:
            print(array[i])
        else:
            print(array[i], end=" ")
             i range(N) range N if i == N-1:
            print(array[i])
        else:
            print(array[i], end=" ")
             i == N-1 i N-1 N 1 print(array[i]) print array[i] array i print(array[i], end=" ") print array[i] array i end=" " end " " array array N N def stable_sort(array_a, array, N):
    for i in range(N-1):
        stable = "yes"
        if array[i][1] == array[i+1][1]:
            index_1 = array.index(array[i])
            index_2 = array.index(array[i+1])
            index_a1 = array_a.index(array[i])
            index_a2 = array_a.index(array[i+1])
            #print(index_1, index_2, index_a1, index_a2)
            if not(index_1 < index_2\
            and index_a1 < index_a2):
                stable = "no"
                break
    if stable == "yes":
        print("Stable")
    else:
        print("Not stable")
             stable_sort for i in range(N-1):
        stable = "yes"
        if array[i][1] == array[i+1][1]:
            index_1 = array.index(array[i])
            index_2 = array.index(array[i+1])
            index_a1 = array_a.index(array[i])
            index_a2 = array_a.index(array[i+1])
            #print(index_1, index_2, index_a1, index_a2)
            if not(index_1 < index_2\
            and index_a1 < index_a2):
                stable = "no"
                break
     i range(N-1) range N-1 N 1 stable = "yes" stable "yes" if array[i][1] == array[i+1][1]:
            index_1 = array.index(array[i])
            index_2 = array.index(array[i+1])
            index_a1 = array_a.index(array[i])
            index_a2 = array_a.index(array[i+1])
            #print(index_1, index_2, index_a1, index_a2)
            if not(index_1 < index_2\
            and index_a1 < index_a2):
                stable = "no"
                break
     array[i][1] == array[i+1][1] array[i][1] [i] array i 1 array[i+1][1] [i+1] array i+1 i 1 1 index_1 = array.index(array[i]) index_1 array.index(array[i]) array.index array index array[i] array i index_2 = array.index(array[i+1]) index_2 array.index(array[i+1]) array.index array index array[i+1] array i+1 i 1 index_a1 = array_a.index(array[i]) index_a1 array_a.index(array[i]) array_a.index array_a index array[i] array i index_a2 = array_a.index(array[i+1]) index_a2 array_a.index(array[i+1]) array_a.index array_a index array[i+1] array i+1 i 1 if not(index_1 < index_2\
            and index_a1 < index_a2):
                stable = "no"
                break
     not(index_1 < index_2\
            and index_a1 < index_a2) index_1 < index_2\
            and index_a1 < index_a2 index_1 < index_2 index_1 index_2 index_a1 < index_a2 index_a1 index_a2 stable = "no" stable "no" break if stable == "yes":
        print("Stable")
    else:
        print("Not stable")
             stable == "yes" stable "yes" print("Stable") print "Stable" print("Not stable") print "Not stable" array_a array_a array array N N N = int(input()) N int(input()) int input() input a = input().split() a input().split() ().split () input split s for s in a for s in a s a for s in a s b = [s for s in a] b [s for s in a] for i in range(N-1):
    for j in range(N-1, i, -1):
        if b[j][1] < b[j-1][1]:
            t = b[j]
            b[j] = b[j-1]
            b[j-1] = t i range(N-1) range N-1 N 1 for j in range(N-1, i, -1):
        if b[j][1] < b[j-1][1]:
            t = b[j]
            b[j] = b[j-1]
            b[j-1] = t j range(N-1, i, -1) range N-1 N 1 i -1 if b[j][1] < b[j-1][1]:
            t = b[j]
            b[j] = b[j-1]
            b[j-1] = t b[j][1] < b[j-1][1] b[j][1] [j] b j 1 b[j-1][1] [j-1] b j-1 j 1 1 t = b[j] t b[j] b j b[j] = b[j-1] b[j] b j b[j-1] b j-1 j 1 b[j-1] = t b[j-1] b j-1 j 1 t print_list(b, N) print_list b N stable_sort(a, b, N) stable_sort a b N s for s in a for s in a s a for s in a s c = [s for s in a] c [s for s in a] for i in range(N-1):
    min_i = c[i][1]
    change = "no"
    for j in range(i+1, N):
        if min_i > c[j][1]:
            min_i = c[j][1]
            index = c.index(c[j])
            change = "ok"
    if change == "ok":
        t = c[i]
        c[i] = c[index]
        c[index] = t i range(N-1) range N-1 N 1 min_i = c[i][1] min_i c[i][1] [i] c i 1 change = "no" change "no" for j in range(i+1, N):
        if min_i > c[j][1]:
            min_i = c[j][1]
            index = c.index(c[j])
            change = "ok"
     j range(i+1, N) range i+1 i 1 N if min_i > c[j][1]:
            min_i = c[j][1]
            index = c.index(c[j])
            change = "ok"
     min_i > c[j][1] min_i c[j][1] [j] c j 1 min_i = c[j][1] min_i c[j][1] [j] c j 1 index = c.index(c[j]) index c.index(c[j]) c.index c index c[j] c j change = "ok" change "ok" if change == "ok":
        t = c[i]
        c[i] = c[index]
        c[index] = t change == "ok" change "ok" t = c[i] t c[i] c i c[i] = c[index] c[i] c i c[index] c index c[index] = t c[index] c index t print_list(c, N) print_list c N stable_sort(a, c, N) stable_sort a c N min_i = c[j][1] c[j][1] min_i change = "ok" "ok" change t = c[i] c[i] t min_i = c[i][1] c[i][1] min_i a = input().split() input().split() a def stable_sort(array_a, array, N):
    for i in range(N-1):
        stable = "yes"
        if array[i][1] == array[i+1][1]:
            index_1 = array.index(array[i])
            index_2 = array.index(array[i+1])
            index_a1 = array_a.index(array[i])
            index_a2 = array_a.index(array[i+1])
            #print(index_1, index_2, index_a1, index_a2)
            if not(index_1 < index_2\
            and index_a1 < index_a2):
                stable = "no"
                break
    if stable == "yes":
        print("Stable")
    else:
        print("Not stable")
             def stable_sort(array_a, array, N):
    for i in range(N-1):
        stable = "yes"
        if array[i][1] == array[i+1][1]:
            index_1 = array.index(array[i])
            index_2 = array.index(array[i+1])
            index_a1 = array_a.index(array[i])
            index_a2 = array_a.index(array[i+1])
            #print(index_1, index_2, index_a1, index_a2)
            if not(index_1 < index_2\
            and index_a1 < index_a2):
                stable = "no"
                break
    if stable == "yes":
        print("Stable")
    else:
        print("Not stable")
             stable_sort N = int(input()) int(input()) N t = b[j] b[j] t change = "no" "no" change b = [s for s in a] [s for s in a] b c = [s for s in a] [s for s in a] c index = c.index(c[j]) c.index(c[j]) index def print_list(array, N):
    for i in range(N):
        if i == N-1:
            print(array[i])
        else:
            print(array[i], end=" ")
             def print_list(array, N):
    for i in range(N):
        if i == N-1:
            print(array[i])
        else:
            print(array[i], end=" ")
             print_list
def print_list(array, N):
    for i in range(N):
        if i == N-1:
            print(array[i])
        else:
            print(array[i], end=" ")
            
def stable_sort(array_a, array, N):
    for i in range(N-1):
        stable = "yes"
        if array[i][1] == array[i+1][1]:
            index_1 = array.index(array[i])
            index_2 = array.index(array[i+1])
            index_a1 = array_a.index(array[i])
            index_a2 = array_a.index(array[i+1])
            #print(index_1, index_2, index_a1, index_a2)
            if not(index_1 < index_2\
            and index_a1 < index_a2):
                stable = "no"
                break
    if stable == "yes":
        print("Stable")
    else:
        print("Not stable")
            
N = int(input())
a = input().split()
b = [s for s in a]
for i in range(N-1):
    for j in range(N-1, i, -1):
        if b[j][1] < b[j-1][1]:
            t = b[j]
            b[j] = b[j-1]
            b[j-1] = t
print_list(b, N)
stable_sort(a, b, N)

c = [s for s in a]
for i in range(N-1):
    min_i = c[i][1]
    change = "no"
    for j in range(i+1, N):
        if min_i > c[j][1]:
            min_i = c[j][1]
            index = c.index(c[j])
            change = "ok"
    if change == "ok":
        t = c[i]
        c[i] = c[index]
        c[index] = t
print_list(c, N)
stable_sort(a, c, N)