n = int(input())
A = input().rstrip().split()
B = list(map(lambda x:int(x[1]), A))
C = list(enumerate(B))
D = list(enumerate(B))

Cb = C
nums = [n - i for i in range(1, n)]
flag = 1

while flag == 1:
    flag = 0
    for j in nums:
        if Cb[j][1] < Cb[j - 1][1]:
            Cb[j], Cb[j - 1] = Cb[j - 1], Cb[j]
            flag = 1
        else:
            pass
Ab = [A[Cb[i][0]] for i in range(n)]
print(*Ab)
bstable = 1
for j in range(n - 1):
    if Cb[j + 1][1] == Cb[j][1] and Cb[j + 1][0] < Cb[j][0]:
        bstable = 0
        break
if bstable == 1:
    print("Stable")
else:
    print("Not stable")

Cs = D
for i in range(n):
    minj = i
    for j in range(i, n):
        if Cs[j][1] < Cs[minj][1]:
            minj = j
        else:
            pass
    Cs[i], Cs[minj] = Cs[minj], Cs[i]
    
As = [A[Cs[i][0]] for i in range(n)]
print(*As)
cstable = 1
for j in range(n - 1):
    if Cs[j + 1][1] == Cs[j][1] and Cs[j + 1][0] < Cs[j][0]:
        cstable = 0
        break
if cstable == 1:
    print("Stable")
else:
    print("Not stable")
 n = int(input()) n int(input()) int input() input A = input().rstrip().split() A input().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () input rstrip split B = list(map(lambda x:int(x[1]), A)) B list(map(lambda x:int(x[1]), A)) list map(lambda x:int(x[1]), A) map lambda x:int(x[1]) int(x[1]) int x[1] x 1 x A C = list(enumerate(B)) C list(enumerate(B)) list enumerate(B) enumerate B D = list(enumerate(B)) D list(enumerate(B)) list enumerate(B) enumerate B Cb = C Cb C n - i for i in range(1, n) for i in range(1, n) i range(1, n) range 1 n for i in range(1, n) n - i n i nums = [n - i for i in range(1, n)] nums [n - i for i in range(1, n)] flag = 1 flag 1 while flag == 1:
    flag = 0
    for j in nums:
        if Cb[j][1] < Cb[j - 1][1]:
            Cb[j], Cb[j - 1] = Cb[j - 1], Cb[j]
            flag = 1
        else:
            pass flag == 1 flag 1 flag = 0 flag 0 for j in nums:
        if Cb[j][1] < Cb[j - 1][1]:
            Cb[j], Cb[j - 1] = Cb[j - 1], Cb[j]
            flag = 1
        else:
            pass j nums if Cb[j][1] < Cb[j - 1][1]:
            Cb[j], Cb[j - 1] = Cb[j - 1], Cb[j]
            flag = 1
        else:
            pass Cb[j][1] < Cb[j - 1][1] Cb[j][1] [j] Cb j 1 Cb[j - 1][1] [j - 1] Cb j - 1 j 1 1 Cb[j], Cb[j - 1] = Cb[j - 1], Cb[j] Cb[j] Cb j Cb[j - 1] Cb j - 1 j 1 Cb[j - 1] Cb j - 1 j 1 Cb[j] Cb j flag = 1 flag 1 A[Cb[i][0]] for i in range(n) for i in range(n) i range(n) range n for i in range(n) A[Cb[i][0]] A Cb[i][0] [i] Cb i 0 Ab = [A[Cb[i][0]] for i in range(n)] Ab [A[Cb[i][0]] for i in range(n)] print(*Ab) print *Ab Ab bstable = 1 bstable 1 for j in range(n - 1):
    if Cb[j + 1][1] == Cb[j][1] and Cb[j + 1][0] < Cb[j][0]:
        bstable = 0
        break j range(n - 1) range n - 1 n 1 if Cb[j + 1][1] == Cb[j][1] and Cb[j + 1][0] < Cb[j][0]:
        bstable = 0
        break Cb[j + 1][1] == Cb[j][1] and Cb[j + 1][0] < Cb[j][0] Cb[j + 1][1] == Cb[j][1] Cb[j + 1][1] [j + 1] Cb j + 1 j 1 1 Cb[j][1] [j] Cb j 1 Cb[j + 1][0] < Cb[j][0] Cb[j + 1][0] [j + 1] Cb j + 1 j 1 0 Cb[j][0] [j] Cb j 0 bstable = 0 bstable 0 break if bstable == 1:
    print("Stable")
else:
    print("Not stable") bstable == 1 bstable 1 print("Stable") print "Stable" print("Not stable") print "Not stable" Cs = D Cs D for i in range(n):
    minj = i
    for j in range(i, n):
        if Cs[j][1] < Cs[minj][1]:
            minj = j
        else:
            pass
    Cs[i], Cs[minj] = Cs[minj], Cs[i]
     i range(n) range n minj = i minj i for j in range(i, n):
        if Cs[j][1] < Cs[minj][1]:
            minj = j
        else:
            pass
     j range(i, n) range i n if Cs[j][1] < Cs[minj][1]:
            minj = j
        else:
            pass
     Cs[j][1] < Cs[minj][1] Cs[j][1] [j] Cs j 1 Cs[minj][1] [minj] Cs minj 1 minj = j minj j Cs[i], Cs[minj] = Cs[minj], Cs[i] Cs[i] Cs i Cs[minj] Cs minj Cs[minj] Cs minj Cs[i] Cs i A[Cs[i][0]] for i in range(n) for i in range(n) i range(n) range n for i in range(n) A[Cs[i][0]] A Cs[i][0] [i] Cs i 0 As = [A[Cs[i][0]] for i in range(n)] As [A[Cs[i][0]] for i in range(n)] print(*As) print *As As cstable = 1 cstable 1 for j in range(n - 1):
    if Cs[j + 1][1] == Cs[j][1] and Cs[j + 1][0] < Cs[j][0]:
        cstable = 0
        break j range(n - 1) range n - 1 n 1 if Cs[j + 1][1] == Cs[j][1] and Cs[j + 1][0] < Cs[j][0]:
        cstable = 0
        break Cs[j + 1][1] == Cs[j][1] and Cs[j + 1][0] < Cs[j][0] Cs[j + 1][1] == Cs[j][1] Cs[j + 1][1] [j + 1] Cs j + 1 j 1 1 Cs[j][1] [j] Cs j 1 Cs[j + 1][0] < Cs[j][0] Cs[j + 1][0] [j + 1] Cs j + 1 j 1 0 Cs[j][0] [j] Cs j 0 cstable = 0 cstable 0 break if cstable == 1:
    print("Stable")
else:
    print("Not stable") cstable == 1 cstable 1 print("Stable") print "Stable" print("Not stable") print "Not stable" Cs = D D Cs Cb = C C Cb flag = 1 1 flag bstable = 1 1 bstable B = list(map(lambda x:int(x[1]), A)) list(map(lambda x:int(x[1]), A)) B C = list(enumerate(B)) list(enumerate(B)) C minj = j j minj n = int(input()) int(input()) n A = input().rstrip().split() input().rstrip().split() A Ab = [A[Cb[i][0]] for i in range(n)] [A[Cb[i][0]] for i in range(n)] Ab cstable = 0 0 cstable flag = 1 1 flag flag = 0 0 flag As = [A[Cs[i][0]] for i in range(n)] [A[Cs[i][0]] for i in range(n)] As D = list(enumerate(B)) list(enumerate(B)) D bstable = 0 0 bstable minj = i i minj cstable = 1 1 cstable nums = [n - i for i in range(1, n)] [n - i for i in range(1, n)] nums
n = int(input())
A = input().rstrip().split()
B = list(map(lambda x:int(x[1]), A))
C = list(enumerate(B))
D = list(enumerate(B))

Cb = C
nums = [n - i for i in range(1, n)]
flag = 1

while flag == 1:
    flag = 0
    for j in nums:
        if Cb[j][1] < Cb[j - 1][1]:
            Cb[j], Cb[j - 1] = Cb[j - 1], Cb[j]
            flag = 1
        else:
            pass
Ab = [A[Cb[i][0]] for i in range(n)]
print(*Ab)
bstable = 1
for j in range(n - 1):
    if Cb[j + 1][1] == Cb[j][1] and Cb[j + 1][0] < Cb[j][0]:
        bstable = 0
        break
if bstable == 1:
    print("Stable")
else:
    print("Not stable")

Cs = D
for i in range(n):
    minj = i
    for j in range(i, n):
        if Cs[j][1] < Cs[minj][1]:
            minj = j
        else:
            pass
    Cs[i], Cs[minj] = Cs[minj], Cs[i]
    
As = [A[Cs[i][0]] for i in range(n)]
print(*As)
cstable = 1
for j in range(n - 1):
    if Cs[j + 1][1] == Cs[j][1] and Cs[j + 1][0] < Cs[j][0]:
        cstable = 0
        break
if cstable == 1:
    print("Stable")
else:
    print("Not stable")

