import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(lambda x: (int(x[1]), x), input().split()))

    # Bubble Sort
    B = A.copy()
    at_least_once = True
    while at_least_once:
        at_least_once = False
        for i in range(N - 1):
            if B[i][0] > B[i + 1][0]:
                B[i], B[i + 1] = B[i + 1], B[i]
                at_least_once = True
    print(" ".join(map(lambda x: x[1], B)))
    print("Stable")

    # Selection Sort
    B = A.copy()
    stability = "Stable"
    for i in range(N - 1):
        min_j = i
        for j in range(i, N):
            if B[j][0] < B[min_j][0]:
                min_j = j
        if min_j != i:
            if B[i][0] in list(map(lambda x: x[0], B[i + 1: min_j])):
                stability = "Not stable"
            B[i], B[min_j] = B[min_j], B[i]
    print(" ".join(map(lambda x: x[1], B)))
    print(stability)


if __name__ == "__main__":
    main()
 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    N = int(input())
    A = list(map(lambda x: (int(x[1]), x), input().split()))

    # Bubble Sort
    B = A.copy()
    at_least_once = True
    while at_least_once:
        at_least_once = False
        for i in range(N - 1):
            if B[i][0] > B[i + 1][0]:
                B[i], B[i + 1] = B[i + 1], B[i]
                at_least_once = True
    print(" ".join(map(lambda x: x[1], B)))
    print("Stable")

    # Selection Sort
    B = A.copy()
    stability = "Stable"
    for i in range(N - 1):
        min_j = i
        for j in range(i, N):
            if B[j][0] < B[min_j][0]:
                min_j = j
        if min_j != i:
            if B[i][0] in list(map(lambda x: x[0], B[i + 1: min_j])):
                stability = "Not stable"
            B[i], B[min_j] = B[min_j], B[i]
    print(" ".join(map(lambda x: x[1], B)))
    print(stability) main N = int(input()) N int(input()) int input() input A = list(map(lambda x: (int(x[1]), x), input().split())) A list(map(lambda x: (int(x[1]), x), input().split())) list map(lambda x: (int(x[1]), x), input().split()) map lambda x: (int(x[1]), x) (int(x[1]), x) int(x[1]) int x[1] x 1 x x input().split() ().split () input split B = A.copy() B A.copy() A.copy A copy at_least_once = True at_least_once True while at_least_once:
        at_least_once = False
        for i in range(N - 1):
            if B[i][0] > B[i + 1][0]:
                B[i], B[i + 1] = B[i + 1], B[i]
                at_least_once = True
     at_least_once at_least_once = False at_least_once False for i in range(N - 1):
            if B[i][0] > B[i + 1][0]:
                B[i], B[i + 1] = B[i + 1], B[i]
                at_least_once = True
     i range(N - 1) range N - 1 N 1 if B[i][0] > B[i + 1][0]:
                B[i], B[i + 1] = B[i + 1], B[i]
                at_least_once = True
     B[i][0] > B[i + 1][0] B[i][0] [i] B i 0 B[i + 1][0] [i + 1] B i + 1 i 1 0 B[i], B[i + 1] = B[i + 1], B[i] B[i] B i B[i + 1] B i + 1 i 1 B[i + 1] B i + 1 i 1 B[i] B i at_least_once = True at_least_once True print(" ".join(map(lambda x: x[1], B))) print " ".join(map(lambda x: x[1], B)) " ".join " " join map(lambda x: x[1], B) map lambda x: x[1] x[1] x 1 x B print("Stable") print "Stable" B = A.copy() B A.copy() A.copy A copy stability = "Stable" stability "Stable" for i in range(N - 1):
        min_j = i
        for j in range(i, N):
            if B[j][0] < B[min_j][0]:
                min_j = j
        if min_j != i:
            if B[i][0] in list(map(lambda x: x[0], B[i + 1: min_j])):
                stability = "Not stable"
            B[i], B[min_j] = B[min_j], B[i]
     i range(N - 1) range N - 1 N 1 min_j = i min_j i for j in range(i, N):
            if B[j][0] < B[min_j][0]:
                min_j = j
         j range(i, N) range i N if B[j][0] < B[min_j][0]:
                min_j = j
         B[j][0] < B[min_j][0] B[j][0] [j] B j 0 B[min_j][0] [min_j] B min_j 0 min_j = j min_j j if min_j != i:
            if B[i][0] in list(map(lambda x: x[0], B[i + 1: min_j])):
                stability = "Not stable"
            B[i], B[min_j] = B[min_j], B[i]
     min_j != i min_j i if B[i][0] in list(map(lambda x: x[0], B[i + 1: min_j])):
                stability = "Not stable"
             B[i][0] in list(map(lambda x: x[0], B[i + 1: min_j])) B[i][0] [i] B i 0 list(map(lambda x: x[0], B[i + 1: min_j])) list map(lambda x: x[0], B[i + 1: min_j]) map lambda x: x[0] x[0] x 0 x B[i + 1: min_j] B i + 1: min_j i + 1 i 1 min_j stability = "Not stable" stability "Not stable" B[i], B[min_j] = B[min_j], B[i] B[i] B i B[min_j] B min_j B[min_j] B min_j B[i] B i print(" ".join(map(lambda x: x[1], B))) print " ".join(map(lambda x: x[1], B)) " ".join " " join map(lambda x: x[1], B) map lambda x: x[1] x[1] x 1 x B print(stability) print stability if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main input = sys.stdin.readline sys.stdin.readline input def main():
    N = int(input())
    A = list(map(lambda x: (int(x[1]), x), input().split()))

    # Bubble Sort
    B = A.copy()
    at_least_once = True
    while at_least_once:
        at_least_once = False
        for i in range(N - 1):
            if B[i][0] > B[i + 1][0]:
                B[i], B[i + 1] = B[i + 1], B[i]
                at_least_once = True
    print(" ".join(map(lambda x: x[1], B)))
    print("Stable")

    # Selection Sort
    B = A.copy()
    stability = "Stable"
    for i in range(N - 1):
        min_j = i
        for j in range(i, N):
            if B[j][0] < B[min_j][0]:
                min_j = j
        if min_j != i:
            if B[i][0] in list(map(lambda x: x[0], B[i + 1: min_j])):
                stability = "Not stable"
            B[i], B[min_j] = B[min_j], B[i]
    print(" ".join(map(lambda x: x[1], B)))
    print(stability) def main():
    N = int(input())
    A = list(map(lambda x: (int(x[1]), x), input().split()))

    # Bubble Sort
    B = A.copy()
    at_least_once = True
    while at_least_once:
        at_least_once = False
        for i in range(N - 1):
            if B[i][0] > B[i + 1][0]:
                B[i], B[i + 1] = B[i + 1], B[i]
                at_least_once = True
    print(" ".join(map(lambda x: x[1], B)))
    print("Stable")

    # Selection Sort
    B = A.copy()
    stability = "Stable"
    for i in range(N - 1):
        min_j = i
        for j in range(i, N):
            if B[j][0] < B[min_j][0]:
                min_j = j
        if min_j != i:
            if B[i][0] in list(map(lambda x: x[0], B[i + 1: min_j])):
                stability = "Not stable"
            B[i], B[min_j] = B[min_j], B[i]
    print(" ".join(map(lambda x: x[1], B)))
    print(stability) main
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(lambda x: (int(x[1]), x), input().split()))

    # Bubble Sort
    B = A.copy()
    at_least_once = True
    while at_least_once:
        at_least_once = False
        for i in range(N - 1):
            if B[i][0] > B[i + 1][0]:
                B[i], B[i + 1] = B[i + 1], B[i]
                at_least_once = True
    print(" ".join(map(lambda x: x[1], B)))
    print("Stable")

    # Selection Sort
    B = A.copy()
    stability = "Stable"
    for i in range(N - 1):
        min_j = i
        for j in range(i, N):
            if B[j][0] < B[min_j][0]:
                min_j = j
        if min_j != i:
            if B[i][0] in list(map(lambda x: x[0], B[i + 1: min_j])):
                stability = "Not stable"
            B[i], B[min_j] = B[min_j], B[i]
    print(" ".join(map(lambda x: x[1], B)))
    print(stability)


if __name__ == "__main__":
    main()

