class Card:
    def __init__(self, name):
        self.name = name
        self.value = int(name[1])
    def __lt__(self, other):
        return self.value < other.value
    def __repr__(self):
        return self.name

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

def selection_sort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j] < C[minj]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C

n = int(input())
cards = [Card(s) for s in input().split()]

bubbled_cards = bubble_sort(cards[:], n)
selected_cards = selection_sort(cards[:], n)
print(' '.join(str(s) for s in bubbled_cards))
print('Stable')
print(' '.join(str(s) for s in selected_cards))
if bubbled_cards == selected_cards:
    print('Stable')
else:
    print('Not stable') class Card:
    def __init__(self, name):
        self.name = name
        self.value = int(name[1])
    def __lt__(self, other):
        return self.value < other.value
    def __repr__(self):
        return self.name Card def __init__(self, name):
        self.name = name
        self.value = int(name[1])
     __init__ self.name = name self.name self name name self.value = int(name[1]) self.value self value int(name[1]) int name[1] name 1 self self name name def __lt__(self, other):
        return self.value < other.value
     __lt__ return self.value < other.value self.value < other.value self.value self value other.value other value self self other other def __repr__(self):
        return self.name __repr__ return self.name self.name self name self self def bubble_sort(C, N):
    for i in range(N):
        for j in range(N-1, i, -1):
            if C[j] < C[j-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] < C[j-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] < C[j-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] < C[j-1]:
                C[j], C[j-1] = C[j-1], C[j]
     C[j] < C[j-1] C[j] C j C[j-1] C j-1 j 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):
        minj = i
        for j in range(i, N):
            if C[j] < C[minj]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C selection_sort for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j] < C[minj]:
                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 C[j] < C[minj]:
                minj = j
         j range(i, N) range i N if C[j] < C[minj]:
                minj = j
         C[j] < C[minj] C[j] C j C[minj] C minj 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 C C N N n = int(input()) n int(input()) int input() input Card(s) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() Card(s) Card s cards = [Card(s) for s in input().split()] cards [Card(s) for s in input().split()] bubbled_cards = bubble_sort(cards[:], n) bubbled_cards bubble_sort(cards[:], n) bubble_sort cards[:] cards : n selected_cards = selection_sort(cards[:], n) selected_cards selection_sort(cards[:], n) selection_sort cards[:] cards : n print(' '.join(str(s) for s in bubbled_cards)) print ' '.join(str(s) for s in bubbled_cards) ' '.join ' ' join str(s) str s print('Stable') print 'Stable' print(' '.join(str(s) for s in selected_cards)) print ' '.join(str(s) for s in selected_cards) ' '.join ' ' join str(s) str s if bubbled_cards == selected_cards:
    print('Stable')
else:
    print('Not stable') bubbled_cards == selected_cards bubbled_cards selected_cards print('Stable') print 'Stable' print('Not stable') print 'Not stable' def bubble_sort(C, N):
    for i in range(N):
        for j in range(N-1, i, -1):
            if C[j] < C[j-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] < C[j-1]:
                C[j], C[j-1] = C[j-1], C[j]
    return C bubble_sort n = int(input()) int(input()) n selected_cards = selection_sort(cards[:], n) selection_sort(cards[:], n) selected_cards class Card:
    def __init__(self, name):
        self.name = name
        self.value = int(name[1])
    def __lt__(self, other):
        return self.value < other.value
    def __repr__(self):
        return self.name class Card:
    def __init__(self, name):
        self.name = name
        self.value = int(name[1])
    def __lt__(self, other):
        return self.value < other.value
    def __repr__(self):
        return self.name Card bubbled_cards = bubble_sort(cards[:], n) bubble_sort(cards[:], n) bubbled_cards def selection_sort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j] < C[minj]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C def selection_sort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j] < C[minj]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C selection_sort cards = [Card(s) for s in input().split()] [Card(s) for s in input().split()] cards
class Card:
    def __init__(self, name):
        self.name = name
        self.value = int(name[1])
    def __lt__(self, other):
        return self.value < other.value
    def __repr__(self):
        return self.name

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

def selection_sort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j] < C[minj]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C

n = int(input())
cards = [Card(s) for s in input().split()]

bubbled_cards = bubble_sort(cards[:], n)
selected_cards = selection_sort(cards[:], n)
print(' '.join(str(s) for s in bubbled_cards))
print('Stable')
print(' '.join(str(s) for s in selected_cards))
if bubbled_cards == selected_cards:
    print('Stable')
else:
    print('Not stable')