import copy
n = int(input())
A = list(map(str,input().split()))
B = copy.copy(A)

def BubbleSort(A,n):
    for i in range(n):
        for j in range(n-1,i,-1):
            if int(A[j][1:2])<int(A[j-1][1:2]):
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
    return A

def SelectionSort(A,n):
    for i in range(n):
        minj = i
        for j in range(i,n):
            if int(A[j][1:2])<int(A[minj][1:2]):
                minj = j
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
    return A

print(' '.join(BubbleSort(A,n)))
print('Stable')
print(' '.join(SelectionSort(B,n)))
if BubbleSort(A,n) == SelectionSort(B,n):
    print('Stable')
else:
    print('Not stable') import copy copy n = int(input()) n int(input()) int input() input A = list(map(str,input().split())) A list(map(str,input().split())) list map(str,input().split()) map str input().split() ().split () input split B = copy.copy(A) B copy.copy(A) copy.copy copy copy A def BubbleSort(A,n):
    for i in range(n):
        for j in range(n-1,i,-1):
            if int(A[j][1:2])<int(A[j-1][1:2]):
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
    return A BubbleSort for i in range(n):
        for j in range(n-1,i,-1):
            if int(A[j][1:2])<int(A[j-1][1:2]):
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
     i range(n) range n for j in range(n-1,i,-1):
            if int(A[j][1:2])<int(A[j-1][1:2]):
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
     j range(n-1,i,-1) range n-1 n 1 i -1 if int(A[j][1:2])<int(A[j-1][1:2]):
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
     int(A[j][1:2])<int(A[j-1][1:2]) int(A[j][1:2]) int A[j][1:2] [j] A j 1:2 1 2 int(A[j-1][1:2]) int A[j-1][1:2] [j-1] A j-1 j 1 1:2 1 2 v = A[j] v A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = v A[j-1] A j-1 j 1 v return A A A A n n def SelectionSort(A,n):
    for i in range(n):
        minj = i
        for j in range(i,n):
            if int(A[j][1:2])<int(A[minj][1:2]):
                minj = j
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
    return A SelectionSort for i in range(n):
        minj = i
        for j in range(i,n):
            if int(A[j][1:2])<int(A[minj][1:2]):
                minj = j
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
     i range(n) range n minj = i minj i for j in range(i,n):
            if int(A[j][1:2])<int(A[minj][1:2]):
                minj = j
         j range(i,n) range i n if int(A[j][1:2])<int(A[minj][1:2]):
                minj = j
         int(A[j][1:2])<int(A[minj][1:2]) int(A[j][1:2]) int A[j][1:2] [j] A j 1:2 1 2 int(A[minj][1:2]) int A[minj][1:2] [minj] A minj 1:2 1 2 minj = j minj j v = A[i] v A[i] A i A[i] = A[minj] A[i] A i A[minj] A minj A[minj] = v A[minj] A minj v return A A A A n n print(' '.join(BubbleSort(A,n))) print ' '.join(BubbleSort(A,n)) ' '.join ' ' join BubbleSort(A,n) BubbleSort A n print('Stable') print 'Stable' print(' '.join(SelectionSort(B,n))) print ' '.join(SelectionSort(B,n)) ' '.join ' ' join SelectionSort(B,n) SelectionSort B n if BubbleSort(A,n) == SelectionSort(B,n):
    print('Stable')
else:
    print('Not stable') BubbleSort(A,n) == SelectionSort(B,n) BubbleSort(A,n) BubbleSort A n SelectionSort(B,n) SelectionSort B n print('Stable') print 'Stable' print('Not stable') print 'Not stable' def BubbleSort(A,n):
    for i in range(n):
        for j in range(n-1,i,-1):
            if int(A[j][1:2])<int(A[j-1][1:2]):
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
    return A def BubbleSort(A,n):
    for i in range(n):
        for j in range(n-1,i,-1):
            if int(A[j][1:2])<int(A[j-1][1:2]):
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
    return A BubbleSort def SelectionSort(A,n):
    for i in range(n):
        minj = i
        for j in range(i,n):
            if int(A[j][1:2])<int(A[minj][1:2]):
                minj = j
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
    return A def SelectionSort(A,n):
    for i in range(n):
        minj = i
        for j in range(i,n):
            if int(A[j][1:2])<int(A[minj][1:2]):
                minj = j
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
    return A SelectionSort n = int(input()) int(input()) n B = copy.copy(A) copy.copy(A) B A = list(map(str,input().split())) list(map(str,input().split())) A
import copy
n = int(input())
A = list(map(str,input().split()))
B = copy.copy(A)

def BubbleSort(A,n):
    for i in range(n):
        for j in range(n-1,i,-1):
            if int(A[j][1:2])<int(A[j-1][1:2]):
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
    return A

def SelectionSort(A,n):
    for i in range(n):
        minj = i
        for j in range(i,n):
            if int(A[j][1:2])<int(A[minj][1:2]):
                minj = j
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
    return A

print(' '.join(BubbleSort(A,n)))
print('Stable')
print(' '.join(SelectionSort(B,n)))
if BubbleSort(A,n) == SelectionSort(B,n):
    print('Stable')
else:
    print('Not stable')
