def BubbleSort(C, N):
    for i in range(N):
        for j in range(N - 1, i, -1):
            if int(C[j][1]) < int(C[j - 1][1]):
                C[j], C[j - 1] = C[j - 1], C[j]
    return C

def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C

def isStable(B, S, N):
    for i in range(N):
        if B[i] != S[i]:
            return False
    return True

N = int(input())
B = input().split()
S = B[:]
B = BubbleSort(B, N)
S = SelectionSort(S, N)
mes = "Stable" if isStable(B, S, N) else "Not stable"
print(" ".join(B))
print("Stable")
print(" ".join(S))
print(mes) def BubbleSort(C, N):
    for i in range(N):
        for j in range(N - 1, i, -1):
            if int(C[j][1]) < int(C[j - 1][1]):
                C[j], C[j - 1] = C[j - 1], C[j]
    return C BubbleSort for i in range(N):
        for j in range(N - 1, i, -1):
            if int(C[j][1]) < int(C[j - 1][1]):
                C[j], C[j - 1] = C[j - 1], C[j]
     i range(N) range N for j in range(N - 1, i, -1):
            if int(C[j][1]) < int(C[j - 1][1]):
                C[j], C[j - 1] = C[j - 1], C[j]
     j range(N - 1, i, -1) range N - 1 N 1 i -1 if int(C[j][1]) < int(C[j - 1][1]):
                C[j], C[j - 1] = C[j - 1], C[j]
     int(C[j][1]) < int(C[j - 1][1]) int(C[j][1]) int C[j][1] [j] C j 1 int(C[j - 1][1]) int C[j - 1][1] [j - 1] C j - 1 j 1 1 C[j], C[j - 1] = C[j - 1], C[j] C[j] C j C[j - 1] C j - 1 j 1 C[j - 1] C j - 1 j 1 C[j] C j return C C C C N N def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C SelectionSort for i in range(N):
        minj = i
        for j in range(i, N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        C[i], C[minj] = C[minj], C[i]
     i range(N) range N minj = i minj i for j in range(i, N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
         j range(i, N) range i N if int(C[j][1]) < int(C[minj][1]):
                minj = j
         int(C[j][1]) < int(C[minj][1]) int(C[j][1]) int C[j][1] [j] C j 1 int(C[minj][1]) int C[minj][1] [minj] C minj 1 minj = j minj j C[i], C[minj] = C[minj], C[i] C[i] C i C[minj] C minj C[minj] C minj C[i] C i return C C C C N N def isStable(B, S, N):
    for i in range(N):
        if B[i] != S[i]:
            return False
    return True isStable for i in range(N):
        if B[i] != S[i]:
            return False
     i range(N) range N if B[i] != S[i]:
            return False
     B[i] != S[i] B[i] B i S[i] S i return False False return True True B B S S N N N = int(input()) N int(input()) int input() input B = input().split() B input().split() ().split () input split S = B[:] S B[:] B : B = BubbleSort(B, N) B BubbleSort(B, N) BubbleSort B N S = SelectionSort(S, N) S SelectionSort(S, N) SelectionSort S N mes = "Stable" if isStable(B, S, N) else "Not stable" mes "Stable" if isStable(B, S, N) else "Not stable" isStable(B, S, N) isStable B S N "Stable" "Not stable" print(" ".join(B)) print " ".join(B) " ".join " " join B print("Stable") print "Stable" print(" ".join(S)) print " ".join(S) " ".join " " join S print(mes) print mes B = input().split() input().split() B N = int(input()) int(input()) N mes = "Stable" if isStable(B, S, N) else "Not stable" "Stable" if isStable(B, S, N) else "Not stable" mes def BubbleSort(C, N):
    for i in range(N):
        for j in range(N - 1, i, -1):
            if int(C[j][1]) < int(C[j - 1][1]):
                C[j], C[j - 1] = C[j - 1], C[j]
    return C def BubbleSort(C, N):
    for i in range(N):
        for j in range(N - 1, i, -1):
            if int(C[j][1]) < int(C[j - 1][1]):
                C[j], C[j - 1] = C[j - 1], C[j]
    return C BubbleSort B = BubbleSort(B, N) BubbleSort(B, N) B def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C SelectionSort def isStable(B, S, N):
    for i in range(N):
        if B[i] != S[i]:
            return False
    return True def isStable(B, S, N):
    for i in range(N):
        if B[i] != S[i]:
            return False
    return True isStable S = SelectionSort(S, N) SelectionSort(S, N) S S = B[:] B[:] S
def BubbleSort(C, N):
    for i in range(N):
        for j in range(N - 1, i, -1):
            if int(C[j][1]) < int(C[j - 1][1]):
                C[j], C[j - 1] = C[j - 1], C[j]
    return C

def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C

def isStable(B, S, N):
    for i in range(N):
        if B[i] != S[i]:
            return False
    return True

N = int(input())
B = input().split()
S = B[:]
B = BubbleSort(B, N)
S = SelectionSort(S, N)
mes = "Stable" if isStable(B, S, N) else "Not stable"
print(" ".join(B))
print("Stable")
print(" ".join(S))
print(mes)