def bubble_sort(a, n):
    for i in range(n-1):
        for j in range(n-1, i, -1):
            if a[j-1][1] > a[j][1]:
                a[j-1], a[j] = a[j], a[j-1]

    return a


def selection_sort(a, n):
    for i in range(n-1):
        min_j = i
        for j in range(i+1, n):
            if a[min_j][1] > a[j][1]:
                min_j = j
        if min_j != i:
            a[min_j], a[i] = a[i], a[min_j]

    return a


if __name__ == "__main__":
    n = int(input())
    a = input().split()

    result1 = bubble_sort(a[:], n)
    result2 = selection_sort(a[:], n)
    print(*result1)
    print("Stable")
    print(*result2)
    print("Stable" if result1 == result2 else "Not stable") def bubble_sort(a, n):
    for i in range(n-1):
        for j in range(n-1, i, -1):
            if a[j-1][1] > a[j][1]:
                a[j-1], a[j] = a[j], a[j-1]

    return a bubble_sort for i in range(n-1):
        for j in range(n-1, i, -1):
            if a[j-1][1] > a[j][1]:
                a[j-1], a[j] = a[j], a[j-1]

     i range(n-1) range n-1 n 1 for j in range(n-1, i, -1):
            if a[j-1][1] > a[j][1]:
                a[j-1], a[j] = a[j], a[j-1]

     j range(n-1, i, -1) range n-1 n 1 i -1 if a[j-1][1] > a[j][1]:
                a[j-1], a[j] = a[j], a[j-1]

     a[j-1][1] > a[j][1] a[j-1][1] [j-1] a j-1 j 1 1 a[j][1] [j] a j 1 a[j-1], a[j] = a[j], a[j-1] a[j-1] a j-1 j 1 a[j] a j a[j] a j a[j-1] a j-1 j 1 return a a a a n n def selection_sort(a, n):
    for i in range(n-1):
        min_j = i
        for j in range(i+1, n):
            if a[min_j][1] > a[j][1]:
                min_j = j
        if min_j != i:
            a[min_j], a[i] = a[i], a[min_j]

    return a selection_sort for i in range(n-1):
        min_j = i
        for j in range(i+1, n):
            if a[min_j][1] > a[j][1]:
                min_j = j
        if min_j != i:
            a[min_j], a[i] = a[i], a[min_j]

     i range(n-1) range n-1 n 1 min_j = i min_j i for j in range(i+1, n):
            if a[min_j][1] > a[j][1]:
                min_j = j
         j range(i+1, n) range i+1 i 1 n if a[min_j][1] > a[j][1]:
                min_j = j
         a[min_j][1] > a[j][1] a[min_j][1] [min_j] a min_j 1 a[j][1] [j] a j 1 min_j = j min_j j if min_j != i:
            a[min_j], a[i] = a[i], a[min_j]

     min_j != i min_j i a[min_j], a[i] = a[i], a[min_j] a[min_j] a min_j a[i] a i a[i] a i a[min_j] a min_j return a a a a n n if __name__ == "__main__":
    n = int(input())
    a = input().split()

    result1 = bubble_sort(a[:], n)
    result2 = selection_sort(a[:], n)
    print(*result1)
    print("Stable")
    print(*result2)
    print("Stable" if result1 == result2 else "Not stable") __name__ == "__main__" __name__ "__main__" n = int(input()) n int(input()) int input() input a = input().split() a input().split() ().split () input split result1 = bubble_sort(a[:], n) result1 bubble_sort(a[:], n) bubble_sort a[:] a : n result2 = selection_sort(a[:], n) result2 selection_sort(a[:], n) selection_sort a[:] a : n print(*result1) print *result1 result1 print("Stable") print "Stable" print(*result2) print *result2 result2 print("Stable" if result1 == result2 else "Not stable") print "Stable" if result1 == result2 else "Not stable" result1 == result2 result1 result2 "Stable" "Not stable" result2 = selection_sort(a[:], n) selection_sort(a[:], n) result2 def selection_sort(a, n):
    for i in range(n-1):
        min_j = i
        for j in range(i+1, n):
            if a[min_j][1] > a[j][1]:
                min_j = j
        if min_j != i:
            a[min_j], a[i] = a[i], a[min_j]

    return a def selection_sort(a, n):
    for i in range(n-1):
        min_j = i
        for j in range(i+1, n):
            if a[min_j][1] > a[j][1]:
                min_j = j
        if min_j != i:
            a[min_j], a[i] = a[i], a[min_j]

    return a selection_sort n = int(input()) int(input()) n a = input().split() input().split() a result1 = bubble_sort(a[:], n) bubble_sort(a[:], n) result1 def bubble_sort(a, n):
    for i in range(n-1):
        for j in range(n-1, i, -1):
            if a[j-1][1] > a[j][1]:
                a[j-1], a[j] = a[j], a[j-1]

    return a def bubble_sort(a, n):
    for i in range(n-1):
        for j in range(n-1, i, -1):
            if a[j-1][1] > a[j][1]:
                a[j-1], a[j] = a[j], a[j-1]

    return a bubble_sort
def bubble_sort(a, n):
    for i in range(n-1):
        for j in range(n-1, i, -1):
            if a[j-1][1] > a[j][1]:
                a[j-1], a[j] = a[j], a[j-1]

    return a


def selection_sort(a, n):
    for i in range(n-1):
        min_j = i
        for j in range(i+1, n):
            if a[min_j][1] > a[j][1]:
                min_j = j
        if min_j != i:
            a[min_j], a[i] = a[i], a[min_j]

    return a


if __name__ == "__main__":
    n = int(input())
    a = input().split()

    result1 = bubble_sort(a[:], n)
    result2 = selection_sort(a[:], n)
    print(*result1)
    print("Stable")
    print(*result2)
    print("Stable" if result1 == result2 else "Not stable")
