def bubblesort(N, A):
    C, flag = [] + A,  True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j- 1], C[j]
                flag = True
    return C

def selectionSort(N, A):
    C = [] + A
    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

N, A= int(input()), input().split()
Ab = bubblesort(N, A)
print(*Ab)
print('Stable')
As = selectionSort(N, A)
print(*As)
if Ab != As:
    print('Not stable')
else:
    print('Stable') def bubblesort(N, A):
    C, flag = [] + A,  True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j- 1], C[j]
                flag = True
    return C bubblesort C, flag = [] + A,  True C [] + A [] A flag True while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j- 1], C[j]
                flag = True
     flag flag = False flag False for j in range(N-1, 0, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j- 1], C[j]
                flag = True
     j range(N-1, 0, -1) range N-1 N 1 0 -1 if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j- 1], C[j]
                flag = True
     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 flag = True flag True return C C N N A A def selectionSort(N, A):
    C = [] + A
    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 C = [] + A C [] + A [] A 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 N N A A N, A= int(input()), input().split() N int(input()) int input() input A input().split() ().split () input split Ab = bubblesort(N, A) Ab bubblesort(N, A) bubblesort N A print(*Ab) print *Ab Ab print('Stable') print 'Stable' As = selectionSort(N, A) As selectionSort(N, A) selectionSort N A print(*As) print *As As if Ab != As:
    print('Not stable')
else:
    print('Stable') Ab != As Ab As print('Not stable') print 'Not stable' print('Stable') print 'Stable' Ab = bubblesort(N, A) bubblesort(N, A) Ab As = selectionSort(N, A) selectionSort(N, A) As A= int(input()), input().split() input().split() A def selectionSort(N, A):
    C = [] + A
    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(N, A):
    C = [] + A
    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 bubblesort(N, A):
    C, flag = [] + A,  True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j- 1], C[j]
                flag = True
    return C def bubblesort(N, A):
    C, flag = [] + A,  True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j- 1], C[j]
                flag = True
    return C bubblesort N, A= int(input()), input().split() int(input()) N
def bubblesort(N, A):
    C, flag = [] + A,  True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j- 1], C[j]
                flag = True
    return C

def selectionSort(N, A):
    C = [] + A
    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

N, A= int(input()), input().split()
Ab = bubblesort(N, A)
print(*Ab)
print('Stable')
As = selectionSort(N, A)
print(*As)
if Ab != As:
    print('Not stable')
else:
    print('Stable')