import copy

def bubbleSort(A):
    flag = 1
    while flag:
        flag = 0
        for j in range(len(A)-1,0,-1):#こういう書き方なんや……逆順処理
            if int(A[j][1]) < int(A[j-1][1]):
                A[j],A[j-1] = A[j-1],A[j]
                flag += 1
    return A

def selectionSort(A):
    for i in range(len(A)):
        minj = i
        for j in range(i,len(A)):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if i != minj:
            A[i],A[minj] = A[minj],A[i]
    return A

N = int(input())
lst1 = list(input().split())
lst2 =  copy.copy(lst1)
print(" ".join(bubbleSort(lst1)))
print("Stable")
print(" ".join(selectionSort(lst2)))
if lst1 == lst2:
    print("Stable")
else:
    print("Not stable") import copy copy def bubbleSort(A):
    flag = 1
    while flag:
        flag = 0
        for j in range(len(A)-1,0,-1):#こういう書き方なんや……逆順処理
            if int(A[j][1]) < int(A[j-1][1]):
                A[j],A[j-1] = A[j-1],A[j]
                flag += 1
    return A bubbleSort flag = 1 flag 1 while flag:
        flag = 0
        for j in range(len(A)-1,0,-1):#こういう書き方なんや……逆順処理
            if int(A[j][1]) < int(A[j-1][1]):
                A[j],A[j-1] = A[j-1],A[j]
                flag += 1
     flag flag = 0 flag 0 for j in range(len(A)-1,0,-1):#こういう書き方なんや……逆順処理
            if int(A[j][1]) < int(A[j-1][1]):
                A[j],A[j-1] = A[j-1],A[j]
                flag += 1
     j range(len(A)-1,0,-1) range len(A)-1 len(A) len A 1 0 -1 if int(A[j][1]) < int(A[j-1][1]):
                A[j],A[j-1] = A[j-1],A[j]
                flag += 1
     int(A[j][1]) < int(A[j-1][1]) int(A[j][1]) int A[j][1] [j] A j 1 int(A[j-1][1]) int A[j-1][1] [j-1] A j-1 j 1 1 A[j],A[j-1] = A[j-1],A[j] A[j] A j A[j-1] A j-1 j 1 A[j-1] A j-1 j 1 A[j] A j flag += 1 flag 1 return A A A A def selectionSort(A):
    for i in range(len(A)):
        minj = i
        for j in range(i,len(A)):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if i != minj:
            A[i],A[minj] = A[minj],A[i]
    return A selectionSort for i in range(len(A)):
        minj = i
        for j in range(i,len(A)):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if i != minj:
            A[i],A[minj] = A[minj],A[i]
     i range(len(A)) range len(A) len A minj = i minj i for j in range(i,len(A)):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
         j range(i,len(A)) range i len(A) len A if int(A[j][1]) < int(A[minj][1]):
                minj = j
         int(A[j][1]) < int(A[minj][1]) int(A[j][1]) int A[j][1] [j] A j 1 int(A[minj][1]) int A[minj][1] [minj] A minj 1 minj = j minj j if i != minj:
            A[i],A[minj] = A[minj],A[i]
     i != minj i minj A[i],A[minj] = A[minj],A[i] A[i] A i A[minj] A minj A[minj] A minj A[i] A i return A A A A N = int(input()) N int(input()) int input() input lst1 = list(input().split()) lst1 list(input().split()) list input().split() ().split () input split lst2 =  copy.copy(lst1) lst2 copy.copy(lst1) copy.copy copy copy lst1 print(" ".join(bubbleSort(lst1))) print " ".join(bubbleSort(lst1)) " ".join " " join bubbleSort(lst1) bubbleSort lst1 print("Stable") print "Stable" print(" ".join(selectionSort(lst2))) print " ".join(selectionSort(lst2)) " ".join " " join selectionSort(lst2) selectionSort lst2 if lst1 == lst2:
    print("Stable")
else:
    print("Not stable") lst1 == lst2 lst1 lst2 print("Stable") print "Stable" print("Not stable") print "Not stable" def bubbleSort(A):
    flag = 1
    while flag:
        flag = 0
        for j in range(len(A)-1,0,-1):#こういう書き方なんや……逆順処理
            if int(A[j][1]) < int(A[j-1][1]):
                A[j],A[j-1] = A[j-1],A[j]
                flag += 1
    return A def bubbleSort(A):
    flag = 1
    while flag:
        flag = 0
        for j in range(len(A)-1,0,-1):#こういう書き方なんや……逆順処理
            if int(A[j][1]) < int(A[j-1][1]):
                A[j],A[j-1] = A[j-1],A[j]
                flag += 1
    return A bubbleSort N = int(input()) int(input()) N lst2 =  copy.copy(lst1) copy.copy(lst1) lst2 def selectionSort(A):
    for i in range(len(A)):
        minj = i
        for j in range(i,len(A)):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if i != minj:
            A[i],A[minj] = A[minj],A[i]
    return A def selectionSort(A):
    for i in range(len(A)):
        minj = i
        for j in range(i,len(A)):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if i != minj:
            A[i],A[minj] = A[minj],A[i]
    return A selectionSort lst1 = list(input().split()) list(input().split()) lst1
import copy

def bubbleSort(A):
    flag = 1
    while flag:
        flag = 0
        for j in range(len(A)-1,0,-1):#こういう書き方なんや……逆順処理
            if int(A[j][1]) < int(A[j-1][1]):
                A[j],A[j-1] = A[j-1],A[j]
                flag += 1
    return A

def selectionSort(A):
    for i in range(len(A)):
        minj = i
        for j in range(i,len(A)):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if i != minj:
            A[i],A[minj] = A[minj],A[i]
    return A

N = int(input())
lst1 = list(input().split())
lst2 =  copy.copy(lst1)
print(" ".join(bubbleSort(lst1)))
print("Stable")
print(" ".join(selectionSort(lst2)))
if lst1 == lst2:
    print("Stable")
else:
    print("Not stable")
