n = int(input())
clist = list(map(list, input().split()))

def BubbleSort(C, n):
    for i in range(n-1):
        for w in range(i+1, n):
            j = n-w+i
            if (C[j][1] < C[j-1][1]):
                a = C[j]
                C[j] = C[j-1]
                C[j-1] = a
def SelectionSort(C, n):
    for i in range(n):
        mini = i
        for j in range(i+1,n):
            if (C[j][1] < C[mini][1]):
                mini = j
        if(mini != i):
            a = C[i]
            C[i] = C[mini]
            C[mini] = a
## l[1]이 str 이라는것에 주의 int(l[1])을 해줘야함 --> 이거 때문에 20분 디버깅 소비
def stable(A,B):
    count = [0 for i in range(9)]
    for l in A:
        count[int(l[1]) - 1] += 1
    ilist = [] ##安定なiのリスト
    for i in range(1,10):
        if (count[i-1] > 1):
            awlist = []
            for l in A:
                if(int(l[1]) == i):
                    awlist.append(l[0])
            bwlist = []
            for l in B:
                if(int(l[1]) == i):
                    bwlist.append(l[0])
            if (awlist == bwlist):
                ilist.append(i)
            
        else:
            ilist.append(i)
    if (len(ilist) == 9):
        print('Stable',end = '')
    else:
        print('Not stable', end = '')
                  

Blist = list(clist)
BubbleSort(Blist, n)
for i in range(n):
    if (i == n-1):
        print('{}{}'.format(Blist[i][0],Blist[i][1]), end = '')
    else : 
        print('{}{}'.format(Blist[i][0],Blist[i][1]), end = ' ')
print()
stable(clist, Blist)
print()

Slist = list(clist)
SelectionSort(Slist, n)
for i in range(n):
    if(i == n-1):
        print('{}{}'.format(Slist[i][0],Slist[i][1]), end = '')
    else:
        print('{}{}'.format(Slist[i][0],Slist[i][1]), end = ' ')
print()
stable(clist, Slist)
print()
 n = int(input()) n int(input()) int input() input clist = list(map(list, input().split())) clist list(map(list, input().split())) list map(list, input().split()) map list input().split() ().split () input split def BubbleSort(C, n):
    for i in range(n-1):
        for w in range(i+1, n):
            j = n-w+i
            if (C[j][1] < C[j-1][1]):
                a = C[j]
                C[j] = C[j-1]
                C[j-1] = a BubbleSort for i in range(n-1):
        for w in range(i+1, n):
            j = n-w+i
            if (C[j][1] < C[j-1][1]):
                a = C[j]
                C[j] = C[j-1]
                C[j-1] = a i range(n-1) range n-1 n 1 for w in range(i+1, n):
            j = n-w+i
            if (C[j][1] < C[j-1][1]):
                a = C[j]
                C[j] = C[j-1]
                C[j-1] = a w range(i+1, n) range i+1 i 1 n j = n-w+i j n-w+i n-w n w i if (C[j][1] < C[j-1][1]):
                a = C[j]
                C[j] = C[j-1]
                C[j-1] = a C[j][1] < C[j-1][1] C[j][1] [j] C j 1 C[j-1][1] [j-1] C j-1 j 1 1 a = C[j] a C[j] C j C[j] = C[j-1] C[j] C j C[j-1] C j-1 j 1 C[j-1] = a C[j-1] C j-1 j 1 a C C n n def SelectionSort(C, n):
    for i in range(n):
        mini = i
        for j in range(i+1,n):
            if (C[j][1] < C[mini][1]):
                mini = j
        if(mini != i):
            a = C[i]
            C[i] = C[mini]
            C[mini] = a
## l[1]이 str 이라는것에 주의 int(l[1])을 해줘야함 --> 이거 때문에 20분 디버깅 소비 SelectionSort for i in range(n):
        mini = i
        for j in range(i+1,n):
            if (C[j][1] < C[mini][1]):
                mini = j
        if(mini != i):
            a = C[i]
            C[i] = C[mini]
            C[mini] = a
## l[1]이 str 이라는것에 주의 int(l[1])을 해줘야함 --> 이거 때문에 20분 디버깅 소비 i range(n) range n mini = i mini i for j in range(i+1,n):
            if (C[j][1] < C[mini][1]):
                mini = j
         j range(i+1,n) range i+1 i 1 n if (C[j][1] < C[mini][1]):
                mini = j
         C[j][1] < C[mini][1] C[j][1] [j] C j 1 C[mini][1] [mini] C mini 1 mini = j mini j if(mini != i):
            a = C[i]
            C[i] = C[mini]
            C[mini] = a
## l[1]이 str 이라는것에 주의 int(l[1])을 해줘야함 --> 이거 때문에 20분 디버깅 소비 mini != i mini i a = C[i] a C[i] C i C[i] = C[mini] C[i] C i C[mini] C mini C[mini] = a C[mini] C mini a C C n n def stable(A,B):
    count = [0 for i in range(9)]
    for l in A:
        count[int(l[1]) - 1] += 1
    ilist = [] ##安定なiのリスト
    for i in range(1,10):
        if (count[i-1] > 1):
            awlist = []
            for l in A:
                if(int(l[1]) == i):
                    awlist.append(l[0])
            bwlist = []
            for l in B:
                if(int(l[1]) == i):
                    bwlist.append(l[0])
            if (awlist == bwlist):
                ilist.append(i)
            
        else:
            ilist.append(i)
    if (len(ilist) == 9):
        print('Stable',end = '')
    else:
        print('Not stable', end = '')
                   stable 0 for i in range(9) for i in range(9) i range(9) range 9 for i in range(9) 0 count = [0 for i in range(9)] count [0 for i in range(9)] for l in A:
        count[int(l[1]) - 1] += 1
     l A count[int(l[1]) - 1] += 1 count[int(l[1]) - 1] count int(l[1]) - 1 int(l[1]) int l[1] l 1 1 1 ilist = [] ilist [] for i in range(1,10):
        if (count[i-1] > 1):
            awlist = []
            for l in A:
                if(int(l[1]) == i):
                    awlist.append(l[0])
            bwlist = []
            for l in B:
                if(int(l[1]) == i):
                    bwlist.append(l[0])
            if (awlist == bwlist):
                ilist.append(i)
            
        else:
            ilist.append(i)
     i range(1,10) range 1 10 if (count[i-1] > 1):
            awlist = []
            for l in A:
                if(int(l[1]) == i):
                    awlist.append(l[0])
            bwlist = []
            for l in B:
                if(int(l[1]) == i):
                    bwlist.append(l[0])
            if (awlist == bwlist):
                ilist.append(i)
            
        else:
            ilist.append(i)
     count[i-1] > 1 count[i-1] count i-1 i 1 1 awlist = [] awlist [] for l in A:
                if(int(l[1]) == i):
                    awlist.append(l[0])
             l A if(int(l[1]) == i):
                    awlist.append(l[0])
             int(l[1]) == i int(l[1]) int l[1] l 1 i awlist.append(l[0]) awlist.append awlist append l[0] l 0 bwlist = [] bwlist [] for l in B:
                if(int(l[1]) == i):
                    bwlist.append(l[0])
             l B if(int(l[1]) == i):
                    bwlist.append(l[0])
             int(l[1]) == i int(l[1]) int l[1] l 1 i bwlist.append(l[0]) bwlist.append bwlist append l[0] l 0 if (awlist == bwlist):
                ilist.append(i)
            
         awlist == bwlist awlist bwlist ilist.append(i) ilist.append ilist append i ilist.append(i) ilist.append ilist append i if (len(ilist) == 9):
        print('Stable',end = '')
    else:
        print('Not stable', end = '')
                   len(ilist) == 9 len(ilist) len ilist 9 print('Stable',end = '') print 'Stable' end = '' end '' print('Not stable', end = '') print 'Not stable' end = '' end '' A A B B Blist = list(clist) Blist list(clist) list clist BubbleSort(Blist, n) BubbleSort Blist n for i in range(n):
    if (i == n-1):
        print('{}{}'.format(Blist[i][0],Blist[i][1]), end = '')
    else : 
        print('{}{}'.format(Blist[i][0],Blist[i][1]), end = ' ') i range(n) range n if (i == n-1):
        print('{}{}'.format(Blist[i][0],Blist[i][1]), end = '')
    else : 
        print('{}{}'.format(Blist[i][0],Blist[i][1]), end = ' ') i == n-1 i n-1 n 1 print('{}{}'.format(Blist[i][0],Blist[i][1]), end = '') print '{}{}'.format(Blist[i][0],Blist[i][1]) '{}{}'.format '{}{}' format Blist[i][0] [i] Blist i 0 Blist[i][1] [i] Blist i 1 end = '' end '' print('{}{}'.format(Blist[i][0],Blist[i][1]), end = ' ') print '{}{}'.format(Blist[i][0],Blist[i][1]) '{}{}'.format '{}{}' format Blist[i][0] [i] Blist i 0 Blist[i][1] [i] Blist i 1 end = ' ' end ' ' print() print stable(clist, Blist) stable clist Blist print() print Slist = list(clist) Slist list(clist) list clist SelectionSort(Slist, n) SelectionSort Slist n for i in range(n):
    if(i == n-1):
        print('{}{}'.format(Slist[i][0],Slist[i][1]), end = '')
    else:
        print('{}{}'.format(Slist[i][0],Slist[i][1]), end = ' ') i range(n) range n if(i == n-1):
        print('{}{}'.format(Slist[i][0],Slist[i][1]), end = '')
    else:
        print('{}{}'.format(Slist[i][0],Slist[i][1]), end = ' ') i == n-1 i n-1 n 1 print('{}{}'.format(Slist[i][0],Slist[i][1]), end = '') print '{}{}'.format(Slist[i][0],Slist[i][1]) '{}{}'.format '{}{}' format Slist[i][0] [i] Slist i 0 Slist[i][1] [i] Slist i 1 end = '' end '' print('{}{}'.format(Slist[i][0],Slist[i][1]), end = ' ') print '{}{}'.format(Slist[i][0],Slist[i][1]) '{}{}'.format '{}{}' format Slist[i][0] [i] Slist i 0 Slist[i][1] [i] Slist i 1 end = ' ' end ' ' print() print stable(clist, Slist) stable clist Slist print() print def stable(A,B):
    count = [0 for i in range(9)]
    for l in A:
        count[int(l[1]) - 1] += 1
    ilist = [] ##安定なiのリスト
    for i in range(1,10):
        if (count[i-1] > 1):
            awlist = []
            for l in A:
                if(int(l[1]) == i):
                    awlist.append(l[0])
            bwlist = []
            for l in B:
                if(int(l[1]) == i):
                    bwlist.append(l[0])
            if (awlist == bwlist):
                ilist.append(i)
            
        else:
            ilist.append(i)
    if (len(ilist) == 9):
        print('Stable',end = '')
    else:
        print('Not stable', end = '')
                   def stable(A,B):
    count = [0 for i in range(9)]
    for l in A:
        count[int(l[1]) - 1] += 1
    ilist = [] ##安定なiのリスト
    for i in range(1,10):
        if (count[i-1] > 1):
            awlist = []
            for l in A:
                if(int(l[1]) == i):
                    awlist.append(l[0])
            bwlist = []
            for l in B:
                if(int(l[1]) == i):
                    bwlist.append(l[0])
            if (awlist == bwlist):
                ilist.append(i)
            
        else:
            ilist.append(i)
    if (len(ilist) == 9):
        print('Stable',end = '')
    else:
        print('Not stable', end = '')
                   stable Blist = list(clist) list(clist) Blist def SelectionSort(C, n):
    for i in range(n):
        mini = i
        for j in range(i+1,n):
            if (C[j][1] < C[mini][1]):
                mini = j
        if(mini != i):
            a = C[i]
            C[i] = C[mini]
            C[mini] = a
## l[1]이 str 이라는것에 주의 int(l[1])을 해줘야함 --> 이거 때문에 20분 디버깅 소비 def SelectionSort(C, n):
    for i in range(n):
        mini = i
        for j in range(i+1,n):
            if (C[j][1] < C[mini][1]):
                mini = j
        if(mini != i):
            a = C[i]
            C[i] = C[mini]
            C[mini] = a
## l[1]이 str 이라는것에 주의 int(l[1])을 해줘야함 --> 이거 때문에 20분 디버깅 소비 SelectionSort n = int(input()) int(input()) n clist = list(map(list, input().split())) list(map(list, input().split())) clist def BubbleSort(C, n):
    for i in range(n-1):
        for w in range(i+1, n):
            j = n-w+i
            if (C[j][1] < C[j-1][1]):
                a = C[j]
                C[j] = C[j-1]
                C[j-1] = a def BubbleSort(C, n):
    for i in range(n-1):
        for w in range(i+1, n):
            j = n-w+i
            if (C[j][1] < C[j-1][1]):
                a = C[j]
                C[j] = C[j-1]
                C[j-1] = a BubbleSort Slist = list(clist) list(clist) Slist
n = int(input())
clist = list(map(list, input().split()))

def BubbleSort(C, n):
    for i in range(n-1):
        for w in range(i+1, n):
            j = n-w+i
            if (C[j][1] < C[j-1][1]):
                a = C[j]
                C[j] = C[j-1]
                C[j-1] = a
def SelectionSort(C, n):
    for i in range(n):
        mini = i
        for j in range(i+1,n):
            if (C[j][1] < C[mini][1]):
                mini = j
        if(mini != i):
            a = C[i]
            C[i] = C[mini]
            C[mini] = a
## l[1]이 str 이라는것에 주의 int(l[1])을 해줘야함 --> 이거 때문에 20분 디버깅 소비
def stable(A,B):
    count = [0 for i in range(9)]
    for l in A:
        count[int(l[1]) - 1] += 1
    ilist = [] ##安定なiのリスト
    for i in range(1,10):
        if (count[i-1] > 1):
            awlist = []
            for l in A:
                if(int(l[1]) == i):
                    awlist.append(l[0])
            bwlist = []
            for l in B:
                if(int(l[1]) == i):
                    bwlist.append(l[0])
            if (awlist == bwlist):
                ilist.append(i)
            
        else:
            ilist.append(i)
    if (len(ilist) == 9):
        print('Stable',end = '')
    else:
        print('Not stable', end = '')
                  

Blist = list(clist)
BubbleSort(Blist, n)
for i in range(n):
    if (i == n-1):
        print('{}{}'.format(Blist[i][0],Blist[i][1]), end = '')
    else : 
        print('{}{}'.format(Blist[i][0],Blist[i][1]), end = ' ')
print()
stable(clist, Blist)
print()

Slist = list(clist)
SelectionSort(Slist, n)
for i in range(n):
    if(i == n-1):
        print('{}{}'.format(Slist[i][0],Slist[i][1]), end = '')
    else:
        print('{}{}'.format(Slist[i][0],Slist[i][1]), end = ' ')
print()
stable(clist, Slist)
print()

