import copy
n = int(input())
c = input().split()
c = [[c[i][0], int(c[i][1])] for i in range(n)]
ba = copy.deepcopy(c)
sa = copy.deepcopy(c)

def bubble_sort(a, n):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in reversed(range(i+1, n)):
            if a[j][1] < a[j-1][1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
        i += 1
    return a

def selection_sort(a, n):
    for i in range(n-1):
        minj = i
        for j in range(i, n):
            if a[j][1] < a[minj][1]:
                minj = j
        a[i], a[minj] = a[minj], a[i]
    return a

ba = bubble_sort(ba, n)
sa = selection_sort(sa, n)

def is_stable(x, y):
    for i in range(n):
        if x[i][0] != y[i][0]:
            return False
    return True

fba = [i[0] + str(i[1]) for i in ba]
print(' '.join(fba))
print('Stable')
fsa = [i[0] + str(i[1]) for i in sa]
print(' '.join(fsa))
print('Stable' if is_stable(ba, sa) else 'Not stable') import copy copy n = int(input()) n int(input()) int input() input c = input().split() c input().split() ().split () input split [c[i][0], int(c[i][1])] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [c[i][0], int(c[i][1])] c[i][0] [i] c i 0 int(c[i][1]) int c[i][1] [i] c i 1 c = [[c[i][0], int(c[i][1])] for i in range(n)] c [[c[i][0], int(c[i][1])] for i in range(n)] ba = copy.deepcopy(c) ba copy.deepcopy(c) copy.deepcopy copy deepcopy c sa = copy.deepcopy(c) sa copy.deepcopy(c) copy.deepcopy copy deepcopy c def bubble_sort(a, n):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in reversed(range(i+1, n)):
            if a[j][1] < a[j-1][1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
        i += 1
    return a bubble_sort flag = 1 flag 1 i = 0 i 0 while flag:
        flag = 0
        for j in reversed(range(i+1, n)):
            if a[j][1] < a[j-1][1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
        i += 1
     flag flag = 0 flag 0 for j in reversed(range(i+1, n)):
            if a[j][1] < a[j-1][1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
         j reversed(range(i+1, n)) reversed range(i+1, n) range i+1 i 1 n if a[j][1] < a[j-1][1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
         a[j][1] < a[j-1][1] a[j][1] [j] a j 1 a[j-1][1] [j-1] a j-1 j 1 1 a[j], a[j-1] = a[j-1], a[j] a[j] a j a[j-1] a j-1 j 1 a[j-1] a j-1 j 1 a[j] a j flag = 1 flag 1 i += 1 i 1 return a a a a n n def selection_sort(a, n):
    for i in range(n-1):
        minj = i
        for j in range(i, n):
            if a[j][1] < a[minj][1]:
                minj = j
        a[i], a[minj] = a[minj], a[i]
    return a selection_sort for i in range(n-1):
        minj = i
        for j in range(i, n):
            if a[j][1] < a[minj][1]:
                minj = j
        a[i], a[minj] = a[minj], a[i]
     i range(n-1) range n-1 n 1 minj = i minj i for j in range(i, n):
            if a[j][1] < a[minj][1]:
                minj = j
         j range(i, n) range i n if a[j][1] < a[minj][1]:
                minj = j
         a[j][1] < a[minj][1] a[j][1] [j] a j 1 a[minj][1] [minj] a minj 1 minj = j minj j a[i], a[minj] = a[minj], a[i] a[i] a i a[minj] a minj a[minj] a minj a[i] a i return a a a a n n ba = bubble_sort(ba, n) ba bubble_sort(ba, n) bubble_sort ba n sa = selection_sort(sa, n) sa selection_sort(sa, n) selection_sort sa n def is_stable(x, y):
    for i in range(n):
        if x[i][0] != y[i][0]:
            return False
    return True is_stable for i in range(n):
        if x[i][0] != y[i][0]:
            return False
     i range(n) range n if x[i][0] != y[i][0]:
            return False
     x[i][0] != y[i][0] x[i][0] [i] x i 0 y[i][0] [i] y i 0 return False False return True True x x y y i[0] + str(i[1]) for i in ba for i in ba i ba for i in ba i[0] + str(i[1]) i[0] i 0 str(i[1]) str i[1] i 1 fba = [i[0] + str(i[1]) for i in ba] fba [i[0] + str(i[1]) for i in ba] print(' '.join(fba)) print ' '.join(fba) ' '.join ' ' join fba print('Stable') print 'Stable' i[0] + str(i[1]) for i in sa for i in sa i sa for i in sa i[0] + str(i[1]) i[0] i 0 str(i[1]) str i[1] i 1 fsa = [i[0] + str(i[1]) for i in sa] fsa [i[0] + str(i[1]) for i in sa] print(' '.join(fsa)) print ' '.join(fsa) ' '.join ' ' join fsa print('Stable' if is_stable(ba, sa) else 'Not stable') print 'Stable' if is_stable(ba, sa) else 'Not stable' is_stable(ba, sa) is_stable ba sa 'Stable' 'Not stable' c = input().split() input().split() c def is_stable(x, y):
    for i in range(n):
        if x[i][0] != y[i][0]:
            return False
    return True def is_stable(x, y):
    for i in range(n):
        if x[i][0] != y[i][0]:
            return False
    return True is_stable fba = [i[0] + str(i[1]) for i in ba] [i[0] + str(i[1]) for i in ba] fba sa = selection_sort(sa, n) selection_sort(sa, n) sa def selection_sort(a, n):
    for i in range(n-1):
        minj = i
        for j in range(i, n):
            if a[j][1] < a[minj][1]:
                minj = j
        a[i], a[minj] = a[minj], a[i]
    return a def selection_sort(a, n):
    for i in range(n-1):
        minj = i
        for j in range(i, n):
            if a[j][1] < a[minj][1]:
                minj = j
        a[i], a[minj] = a[minj], a[i]
    return a selection_sort n = int(input()) int(input()) n def bubble_sort(a, n):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in reversed(range(i+1, n)):
            if a[j][1] < a[j-1][1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
        i += 1
    return a def bubble_sort(a, n):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in reversed(range(i+1, n)):
            if a[j][1] < a[j-1][1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
        i += 1
    return a bubble_sort ba = bubble_sort(ba, n) bubble_sort(ba, n) ba sa = copy.deepcopy(c) copy.deepcopy(c) sa fsa = [i[0] + str(i[1]) for i in sa] [i[0] + str(i[1]) for i in sa] fsa c = [[c[i][0], int(c[i][1])] for i in range(n)] [[c[i][0], int(c[i][1])] for i in range(n)] c ba = copy.deepcopy(c) copy.deepcopy(c) ba
import copy
n = int(input())
c = input().split()
c = [[c[i][0], int(c[i][1])] for i in range(n)]
ba = copy.deepcopy(c)
sa = copy.deepcopy(c)

def bubble_sort(a, n):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in reversed(range(i+1, n)):
            if a[j][1] < a[j-1][1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
        i += 1
    return a

def selection_sort(a, n):
    for i in range(n-1):
        minj = i
        for j in range(i, n):
            if a[j][1] < a[minj][1]:
                minj = j
        a[i], a[minj] = a[minj], a[i]
    return a

ba = bubble_sort(ba, n)
sa = selection_sort(sa, n)

def is_stable(x, y):
    for i in range(n):
        if x[i][0] != y[i][0]:
            return False
    return True

fba = [i[0] + str(i[1]) for i in ba]
print(' '.join(fba))
print('Stable')
fsa = [i[0] + str(i[1]) for i in sa]
print(' '.join(fsa))
print('Stable' if is_stable(ba, sa) else 'Not stable')
