def print_list(array):
    for i,e in enumerate(array):
        if i == N - 1:
            print(e)
        else:
            print(e, end=" ")

def bubbleSort():
    for i in range(N-1):
        for j in range(N-1, i, -1):
            if int(A[j][1:]) < int(A[j-1][1:]):
                w = A[j]; A[j] = A[j-1]; A[j-1] = w

def selectionSort():
    for i in range(N):
        min_index = i
        for j in range(i, N):
            if int(B[min_index][1:]) > int(B[j][1:]):
                min_index = j
        if i != min_index:
            w = B[i]; B[i] = B[min_index]; B[min_index] = w

N = int(input())
A = input().split()
B = list(A)
bubbleSort()
print_list(A)
print("Stable")
selectionSort()
print_list(B)
if A == B:
    print("Stable")
else:
    print("Not stable")
 def print_list(array):
    for i,e in enumerate(array):
        if i == N - 1:
            print(e)
        else:
            print(e, end=" ") print_list for i,e in enumerate(array):
        if i == N - 1:
            print(e)
        else:
            print(e, end=" ") i e enumerate(array) enumerate array if i == N - 1:
            print(e)
        else:
            print(e, end=" ") i == N - 1 i N - 1 N 1 print(e) print e print(e, end=" ") print e end=" " end " " array array def bubbleSort():
    for i in range(N-1):
        for j in range(N-1, i, -1):
            if int(A[j][1:]) < int(A[j-1][1:]):
                w = A[j]; A[j] = A[j-1]; A[j-1] = w bubbleSort for i in range(N-1):
        for j in range(N-1, i, -1):
            if int(A[j][1:]) < int(A[j-1][1:]):
                w = A[j]; A[j] = A[j-1]; A[j-1] = w i range(N-1) range N-1 N 1 for j in range(N-1, i, -1):
            if int(A[j][1:]) < int(A[j-1][1:]):
                w = A[j]; A[j] = A[j-1]; A[j-1] = w j range(N-1, i, -1) range N-1 N 1 i -1 if int(A[j][1:]) < int(A[j-1][1:]):
                w = A[j]; A[j] = A[j-1]; A[j-1] = w int(A[j][1:]) < int(A[j-1][1:]) int(A[j][1:]) int A[j][1:] [j] A j 1: 1 int(A[j-1][1:]) int A[j-1][1:] [j-1] A j-1 j 1 1: 1 w = A[j] w A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = w A[j-1] A j-1 j 1 w def selectionSort():
    for i in range(N):
        min_index = i
        for j in range(i, N):
            if int(B[min_index][1:]) > int(B[j][1:]):
                min_index = j
        if i != min_index:
            w = B[i]; B[i] = B[min_index]; B[min_index] = w selectionSort for i in range(N):
        min_index = i
        for j in range(i, N):
            if int(B[min_index][1:]) > int(B[j][1:]):
                min_index = j
        if i != min_index:
            w = B[i]; B[i] = B[min_index]; B[min_index] = w i range(N) range N min_index = i min_index i for j in range(i, N):
            if int(B[min_index][1:]) > int(B[j][1:]):
                min_index = j
         j range(i, N) range i N if int(B[min_index][1:]) > int(B[j][1:]):
                min_index = j
         int(B[min_index][1:]) > int(B[j][1:]) int(B[min_index][1:]) int B[min_index][1:] [min_index] B min_index 1: 1 int(B[j][1:]) int B[j][1:] [j] B j 1: 1 min_index = j min_index j if i != min_index:
            w = B[i]; B[i] = B[min_index]; B[min_index] = w i != min_index i min_index w = B[i] w B[i] B i B[i] = B[min_index] B[i] B i B[min_index] B min_index B[min_index] = w B[min_index] B min_index w N = int(input()) N int(input()) int input() input A = input().split() A input().split() ().split () input split B = list(A) B list(A) list A bubbleSort() bubbleSort print_list(A) print_list A print("Stable") print "Stable" selectionSort() selectionSort print_list(B) print_list B if A == B:
    print("Stable")
else:
    print("Not stable") A == B A B print("Stable") print "Stable" print("Not stable") print "Not stable" def print_list(array):
    for i,e in enumerate(array):
        if i == N - 1:
            print(e)
        else:
            print(e, end=" ") def print_list(array):
    for i,e in enumerate(array):
        if i == N - 1:
            print(e)
        else:
            print(e, end=" ") print_list def bubbleSort():
    for i in range(N-1):
        for j in range(N-1, i, -1):
            if int(A[j][1:]) < int(A[j-1][1:]):
                w = A[j]; A[j] = A[j-1]; A[j-1] = w def bubbleSort():
    for i in range(N-1):
        for j in range(N-1, i, -1):
            if int(A[j][1:]) < int(A[j-1][1:]):
                w = A[j]; A[j] = A[j-1]; A[j-1] = w bubbleSort def selectionSort():
    for i in range(N):
        min_index = i
        for j in range(i, N):
            if int(B[min_index][1:]) > int(B[j][1:]):
                min_index = j
        if i != min_index:
            w = B[i]; B[i] = B[min_index]; B[min_index] = w def selectionSort():
    for i in range(N):
        min_index = i
        for j in range(i, N):
            if int(B[min_index][1:]) > int(B[j][1:]):
                min_index = j
        if i != min_index:
            w = B[i]; B[i] = B[min_index]; B[min_index] = w selectionSort A = input().split() input().split() A N = int(input()) int(input()) N B = list(A) list(A) B
def print_list(array):
    for i,e in enumerate(array):
        if i == N - 1:
            print(e)
        else:
            print(e, end=" ")

def bubbleSort():
    for i in range(N-1):
        for j in range(N-1, i, -1):
            if int(A[j][1:]) < int(A[j-1][1:]):
                w = A[j]; A[j] = A[j-1]; A[j-1] = w

def selectionSort():
    for i in range(N):
        min_index = i
        for j in range(i, N):
            if int(B[min_index][1:]) > int(B[j][1:]):
                min_index = j
        if i != min_index:
            w = B[i]; B[i] = B[min_index]; B[min_index] = w

N = int(input())
A = input().split()
B = list(A)
bubbleSort()
print_list(A)
print("Stable")
selectionSort()
print_list(B)
if A == B:
    print("Stable")
else:
    print("Not stable")

