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

def selection_sort(c, n):
    for i in range(n-1):
        minj = i
        for j in range(i+1, n):
            if c[j][1] < c[minj][1]:
                minj = j
        if i != j:
            c[i], c[minj] = c[minj], c[i]
    return c


def main():
    N = int(input())
    cards1 = input().split()
    cards2 = cards1.copy()

    bubble_sorted = bubble_sort(cards1, N)
    print(*bubble_sorted)
    print("Stable")
    
    select_sorted = selection_sort(cards2, N)
    print(*select_sorted)
    if bubble_sorted == select_sorted:
        print("Stable")
    else:
        print("Not stable")


if __name__ == "__main__":
    main()
 def bubble_sort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if c[j][1] < c[j-1][1]:
                c[j], c[j-1] = c[j-1], c[j]
    return c bubble_sort for i in range(n):
        for j in range(n-1, i, -1):
            if c[j][1] < 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 c[j][1] < 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 c[j][1] < c[j-1][1]:
                c[j], c[j-1] = c[j-1], c[j]
     c[j][1] < c[j-1][1] c[j][1] [j] c j 1 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 selection_sort(c, n):
    for i in range(n-1):
        minj = i
        for j in range(i+1, n):
            if c[j][1] < c[minj][1]:
                minj = j
        if i != j:
            c[i], c[minj] = c[minj], c[i]
    return c selection_sort for i in range(n-1):
        minj = i
        for j in range(i+1, n):
            if c[j][1] < c[minj][1]:
                minj = j
        if i != j:
            c[i], c[minj] = c[minj], c[i]
     i range(n-1) range n-1 n 1 minj = i minj i for j in range(i+1, n):
            if c[j][1] < c[minj][1]:
                minj = j
         j range(i+1, n) range i+1 i 1 n if c[j][1] < c[minj][1]:
                minj = j
         c[j][1] < c[minj][1] c[j][1] [j] c j 1 c[minj][1] [minj] c minj 1 minj = j minj j if i != j:
            c[i], c[minj] = c[minj], c[i]
     i != j i 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 main():
    N = int(input())
    cards1 = input().split()
    cards2 = cards1.copy()

    bubble_sorted = bubble_sort(cards1, N)
    print(*bubble_sorted)
    print("Stable")
    
    select_sorted = selection_sort(cards2, N)
    print(*select_sorted)
    if bubble_sorted == select_sorted:
        print("Stable")
    else:
        print("Not stable") main N = int(input()) N int(input()) int input() input cards1 = input().split() cards1 input().split() ().split () input split cards2 = cards1.copy() cards2 cards1.copy() cards1.copy cards1 copy bubble_sorted = bubble_sort(cards1, N) bubble_sorted bubble_sort(cards1, N) bubble_sort cards1 N print(*bubble_sorted) print *bubble_sorted bubble_sorted print("Stable") print "Stable" select_sorted = selection_sort(cards2, N) select_sorted selection_sort(cards2, N) selection_sort cards2 N print(*select_sorted) print *select_sorted select_sorted if bubble_sorted == select_sorted:
        print("Stable")
    else:
        print("Not stable") bubble_sorted == select_sorted bubble_sorted select_sorted print("Stable") print "Stable" print("Not stable") print "Not stable" if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N = int(input())
    cards1 = input().split()
    cards2 = cards1.copy()

    bubble_sorted = bubble_sort(cards1, N)
    print(*bubble_sorted)
    print("Stable")
    
    select_sorted = selection_sort(cards2, N)
    print(*select_sorted)
    if bubble_sorted == select_sorted:
        print("Stable")
    else:
        print("Not stable") def main():
    N = int(input())
    cards1 = input().split()
    cards2 = cards1.copy()

    bubble_sorted = bubble_sort(cards1, N)
    print(*bubble_sorted)
    print("Stable")
    
    select_sorted = selection_sort(cards2, N)
    print(*select_sorted)
    if bubble_sorted == select_sorted:
        print("Stable")
    else:
        print("Not stable") main def bubble_sort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if c[j][1] < c[j-1][1]:
                c[j], c[j-1] = c[j-1], c[j]
    return c def bubble_sort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if c[j][1] < c[j-1][1]:
                c[j], c[j-1] = c[j-1], c[j]
    return c bubble_sort def selection_sort(c, n):
    for i in range(n-1):
        minj = i
        for j in range(i+1, n):
            if c[j][1] < c[minj][1]:
                minj = j
        if i != j:
            c[i], c[minj] = c[minj], c[i]
    return c def selection_sort(c, n):
    for i in range(n-1):
        minj = i
        for j in range(i+1, n):
            if c[j][1] < c[minj][1]:
                minj = j
        if i != j:
            c[i], c[minj] = c[minj], c[i]
    return c selection_sort
def bubble_sort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if c[j][1] < c[j-1][1]:
                c[j], c[j-1] = c[j-1], c[j]
    return c

def selection_sort(c, n):
    for i in range(n-1):
        minj = i
        for j in range(i+1, n):
            if c[j][1] < c[minj][1]:
                minj = j
        if i != j:
            c[i], c[minj] = c[minj], c[i]
    return c


def main():
    N = int(input())
    cards1 = input().split()
    cards2 = cards1.copy()

    bubble_sorted = bubble_sort(cards1, N)
    print(*bubble_sorted)
    print("Stable")
    
    select_sorted = selection_sort(cards2, N)
    print(*select_sorted)
    if bubble_sorted == select_sorted:
        print("Stable")
    else:
        print("Not stable")


if __name__ == "__main__":
    main()

