# 配列の宣言
A = []
B = []

# 文字列の取得と加工
LENGTH =int(input())
A = input().split()
B = A.copy()

def bubble (A, LENGTH):
    N = 0
    M = LENGTH - 1
    CHANGE = 0

    while N <= LENGTH -1:
        M = LENGTH - 1
        while M >= N + 1:
            if int(A[M][1:]) < int(A[M-1][1:]):
                tmp = A[M-1]
                A[M-1] = A[M]
                A[M] = tmp
                CHANGE += 1
            M -= 1
        N += 1

    print(" ".join(map(str,A)))
    print("Stable")

def selection (B, LENGTH):
    i = 0
    CHANGE_COUNT = 0

    while i <= LENGTH -1:
        j = i + 1
        mini = i
        while j <= LENGTH -1:
            if int(B[j][1:]) < int(B[mini][1:]):
                mini = j
            j += 1
        if mini != i:
            tmp = B[i]
            B[i] = B[mini]
            B[mini] = tmp
            CHANGE_COUNT += 1
        i += 1

    print(" ".join(map(str,B)))
    if A == B:
        print("Stable")
    else:
        print("Not stable")

bubble (A, LENGTH)
selection (B, LENGTH) A = [] A [] B = [] B [] LENGTH =int(input()) LENGTH int(input()) int input() input A = input().split() A input().split() ().split () input split B = A.copy() B A.copy() A.copy A copy def bubble (A, LENGTH):
    N = 0
    M = LENGTH - 1
    CHANGE = 0

    while N <= LENGTH -1:
        M = LENGTH - 1
        while M >= N + 1:
            if int(A[M][1:]) < int(A[M-1][1:]):
                tmp = A[M-1]
                A[M-1] = A[M]
                A[M] = tmp
                CHANGE += 1
            M -= 1
        N += 1

    print(" ".join(map(str,A)))
    print("Stable") bubble N = 0 N 0 M = LENGTH - 1 M LENGTH - 1 LENGTH 1 CHANGE = 0 CHANGE 0 while N <= LENGTH -1:
        M = LENGTH - 1
        while M >= N + 1:
            if int(A[M][1:]) < int(A[M-1][1:]):
                tmp = A[M-1]
                A[M-1] = A[M]
                A[M] = tmp
                CHANGE += 1
            M -= 1
        N += 1

     N <= LENGTH -1 N LENGTH -1 LENGTH 1 M = LENGTH - 1 M LENGTH - 1 LENGTH 1 while M >= N + 1:
            if int(A[M][1:]) < int(A[M-1][1:]):
                tmp = A[M-1]
                A[M-1] = A[M]
                A[M] = tmp
                CHANGE += 1
            M -= 1
         M >= N + 1 M N + 1 N 1 if int(A[M][1:]) < int(A[M-1][1:]):
                tmp = A[M-1]
                A[M-1] = A[M]
                A[M] = tmp
                CHANGE += 1
             int(A[M][1:]) < int(A[M-1][1:]) int(A[M][1:]) int A[M][1:] [M] A M 1: 1 int(A[M-1][1:]) int A[M-1][1:] [M-1] A M-1 M 1 1: 1 tmp = A[M-1] tmp A[M-1] A M-1 M 1 A[M-1] = A[M] A[M-1] A M-1 M 1 A[M] A M A[M] = tmp A[M] A M tmp CHANGE += 1 CHANGE 1 M -= 1 M 1 N += 1 N 1 print(" ".join(map(str,A))) print " ".join(map(str,A)) " ".join " " join map(str,A) map str A print("Stable") print "Stable" A A LENGTH LENGTH def selection (B, LENGTH):
    i = 0
    CHANGE_COUNT = 0

    while i <= LENGTH -1:
        j = i + 1
        mini = i
        while j <= LENGTH -1:
            if int(B[j][1:]) < int(B[mini][1:]):
                mini = j
            j += 1
        if mini != i:
            tmp = B[i]
            B[i] = B[mini]
            B[mini] = tmp
            CHANGE_COUNT += 1
        i += 1

    print(" ".join(map(str,B)))
    if A == B:
        print("Stable")
    else:
        print("Not stable") selection i = 0 i 0 CHANGE_COUNT = 0 CHANGE_COUNT 0 while i <= LENGTH -1:
        j = i + 1
        mini = i
        while j <= LENGTH -1:
            if int(B[j][1:]) < int(B[mini][1:]):
                mini = j
            j += 1
        if mini != i:
            tmp = B[i]
            B[i] = B[mini]
            B[mini] = tmp
            CHANGE_COUNT += 1
        i += 1

     i <= LENGTH -1 i LENGTH -1 LENGTH 1 j = i + 1 j i + 1 i 1 mini = i mini i while j <= LENGTH -1:
            if int(B[j][1:]) < int(B[mini][1:]):
                mini = j
            j += 1
         j <= LENGTH -1 j LENGTH -1 LENGTH 1 if int(B[j][1:]) < int(B[mini][1:]):
                mini = j
             int(B[j][1:]) < int(B[mini][1:]) int(B[j][1:]) int B[j][1:] [j] B j 1: 1 int(B[mini][1:]) int B[mini][1:] [mini] B mini 1: 1 mini = j mini j j += 1 j 1 if mini != i:
            tmp = B[i]
            B[i] = B[mini]
            B[mini] = tmp
            CHANGE_COUNT += 1
         mini != i mini i tmp = B[i] tmp B[i] B i B[i] = B[mini] B[i] B i B[mini] B mini B[mini] = tmp B[mini] B mini tmp CHANGE_COUNT += 1 CHANGE_COUNT 1 i += 1 i 1 print(" ".join(map(str,B))) print " ".join(map(str,B)) " ".join " " join map(str,B) map str B if A == B:
        print("Stable")
    else:
        print("Not stable") A == B A B print("Stable") print "Stable" print("Not stable") print "Not stable" B B LENGTH LENGTH bubble (A, LENGTH) bubble A LENGTH selection (B, LENGTH) selection B LENGTH A = input().split() input().split() A def bubble (A, LENGTH):
    N = 0
    M = LENGTH - 1
    CHANGE = 0

    while N <= LENGTH -1:
        M = LENGTH - 1
        while M >= N + 1:
            if int(A[M][1:]) < int(A[M-1][1:]):
                tmp = A[M-1]
                A[M-1] = A[M]
                A[M] = tmp
                CHANGE += 1
            M -= 1
        N += 1

    print(" ".join(map(str,A)))
    print("Stable") def bubble (A, LENGTH):
    N = 0
    M = LENGTH - 1
    CHANGE = 0

    while N <= LENGTH -1:
        M = LENGTH - 1
        while M >= N + 1:
            if int(A[M][1:]) < int(A[M-1][1:]):
                tmp = A[M-1]
                A[M-1] = A[M]
                A[M] = tmp
                CHANGE += 1
            M -= 1
        N += 1

    print(" ".join(map(str,A)))
    print("Stable") bubble B = [] [] B B = A.copy() A.copy() B A = [] [] A LENGTH =int(input()) int(input()) LENGTH def selection (B, LENGTH):
    i = 0
    CHANGE_COUNT = 0

    while i <= LENGTH -1:
        j = i + 1
        mini = i
        while j <= LENGTH -1:
            if int(B[j][1:]) < int(B[mini][1:]):
                mini = j
            j += 1
        if mini != i:
            tmp = B[i]
            B[i] = B[mini]
            B[mini] = tmp
            CHANGE_COUNT += 1
        i += 1

    print(" ".join(map(str,B)))
    if A == B:
        print("Stable")
    else:
        print("Not stable") def selection (B, LENGTH):
    i = 0
    CHANGE_COUNT = 0

    while i <= LENGTH -1:
        j = i + 1
        mini = i
        while j <= LENGTH -1:
            if int(B[j][1:]) < int(B[mini][1:]):
                mini = j
            j += 1
        if mini != i:
            tmp = B[i]
            B[i] = B[mini]
            B[mini] = tmp
            CHANGE_COUNT += 1
        i += 1

    print(" ".join(map(str,B)))
    if A == B:
        print("Stable")
    else:
        print("Not stable") selection
# 配列の宣言
A = []
B = []

# 文字列の取得と加工
LENGTH =int(input())
A = input().split()
B = A.copy()

def bubble (A, LENGTH):
    N = 0
    M = LENGTH - 1
    CHANGE = 0

    while N <= LENGTH -1:
        M = LENGTH - 1
        while M >= N + 1:
            if int(A[M][1:]) < int(A[M-1][1:]):
                tmp = A[M-1]
                A[M-1] = A[M]
                A[M] = tmp
                CHANGE += 1
            M -= 1
        N += 1

    print(" ".join(map(str,A)))
    print("Stable")

def selection (B, LENGTH):
    i = 0
    CHANGE_COUNT = 0

    while i <= LENGTH -1:
        j = i + 1
        mini = i
        while j <= LENGTH -1:
            if int(B[j][1:]) < int(B[mini][1:]):
                mini = j
            j += 1
        if mini != i:
            tmp = B[i]
            B[i] = B[mini]
            B[mini] = tmp
            CHANGE_COUNT += 1
        i += 1

    print(" ".join(map(str,B)))
    if A == B:
        print("Stable")
    else:
        print("Not stable")

bubble (A, LENGTH)
selection (B, LENGTH)
