# coding: utf-8

def bubbleSort(C, N):
    for i in xrange(N):
        for j in xrange(N-1, i, -1):
            if C[j-1][1] > C[j][1]:
                C[j], C[j-1] = C[j-1], C[j]
    return C

def selectionSort(C, N):
    for i in xrange(N):
        minj = i
        for j in xrange(i, N):
            if C[minj][1] > C[j][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C

def isStable(in_, out_, N):
    for i in xrange(N):
        for j in xrange(i + 1, N):
            for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
    return True

def main():
    N = input()
    cards = raw_input().split()
    bubble = bubbleSort(cards[:], N)
    selection = selectionSort(cards[:], N)
    print ' '.join(bubble)
    print 'Stable' if isStable(cards, bubble, N) else 'Not stable'
    print ' '.join(selection)
    print 'Stable' if isStable(cards, selection, N) else 'Not stable'



if __name__ == '__main__':
    main() def bubbleSort(C, N):
    for i in xrange(N):
        for j in xrange(N-1, i, -1):
            if C[j-1][1] > C[j][1]:
                C[j], C[j-1] = C[j-1], C[j]
    return C bubbleSort for i in xrange(N):
        for j in xrange(N-1, i, -1):
            if C[j-1][1] > C[j][1]:
                C[j], C[j-1] = C[j-1], C[j]
     i xrange(N) xrange N for j in xrange(N-1, i, -1):
            if C[j-1][1] > C[j][1]:
                C[j], C[j-1] = C[j-1], C[j]
     j xrange(N-1, i, -1) xrange N-1 N 1 i -1 if C[j-1][1] > C[j][1]:
                C[j], C[j-1] = C[j-1], C[j]
     C[j-1][1] > C[j][1] C[j-1][1] [j-1] C j-1 j 1 1 C[j][1] [j] C 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 selectionSort(C, N):
    for i in xrange(N):
        minj = i
        for j in xrange(i, N):
            if C[minj][1] > C[j][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C selectionSort for i in xrange(N):
        minj = i
        for j in xrange(i, N):
            if C[minj][1] > C[j][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
     i xrange(N) xrange N minj = i minj i for j in xrange(i, N):
            if C[minj][1] > C[j][1]:
                minj = j
         j xrange(i, N) xrange i N if C[minj][1] > C[j][1]:
                minj = j
         C[minj][1] > C[j][1] C[minj][1] [minj] C minj 1 C[j][1] [j] C j 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 C C N N def isStable(in_, out_, N):
    for i in xrange(N):
        for j in xrange(i + 1, N):
            for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
    return True isStable for i in xrange(N):
        for j in xrange(i + 1, N):
            for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
     i xrange(N) xrange N for j in xrange(i + 1, N):
            for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
     j xrange(i + 1, N) xrange i + 1 i 1 N for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
     a xrange(N) xrange N for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
     b xrange(a + 1, N) xrange a + 1 a 1 N if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
     in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a] in_[i][1] == in_[j][1] and in_[i] == out_[b] in_[i][1] == in_[j][1] in_[i][1] [i] in_ i 1 in_[j][1] [j] in_ j 1 in_[i] == out_[b] in_[i] in_ i out_[b] out_ b in_[j] == out_[a] in_[j] in_ j out_[a] out_ a return False False return True True in_ in_ out_ out_ N N def main():
    N = input()
    cards = raw_input().split()
    bubble = bubbleSort(cards[:], N)
    selection = selectionSort(cards[:], N)
    print ' '.join(bubble)
    print 'Stable' if isStable(cards, bubble, N) else 'Not stable'
    print ' '.join(selection)
    print 'Stable' if isStable(cards, selection, N) else 'Not stable' main N = input() N input() input cards = raw_input().split() cards raw_input().split() ().split () raw_input split bubble = bubbleSort(cards[:], N) bubble bubbleSort(cards[:], N) bubbleSort cards[:] cards : N selection = selectionSort(cards[:], N) selection selectionSort(cards[:], N) selectionSort cards[:] cards : N print ' '.join(bubble) ' '.join ' ' join bubble print 'Stable' if isStable(cards, bubble, N) else 'Not stable' isStable(cards, bubble, N) isStable cards bubble N 'Stable' 'Not stable' print ' '.join(selection) ' '.join ' ' join selection print 'Stable' if isStable(cards, selection, N) else 'Not stable' isStable(cards, selection, N) isStable cards selection N 'Stable' 'Not stable' if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def isStable(in_, out_, N):
    for i in xrange(N):
        for j in xrange(i + 1, N):
            for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
    return True def isStable(in_, out_, N):
    for i in xrange(N):
        for j in xrange(i + 1, N):
            for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
    return True isStable def bubbleSort(C, N):
    for i in xrange(N):
        for j in xrange(N-1, i, -1):
            if C[j-1][1] > C[j][1]:
                C[j], C[j-1] = C[j-1], C[j]
    return C def bubbleSort(C, N):
    for i in xrange(N):
        for j in xrange(N-1, i, -1):
            if C[j-1][1] > C[j][1]:
                C[j], C[j-1] = C[j-1], C[j]
    return C bubbleSort def selectionSort(C, N):
    for i in xrange(N):
        minj = i
        for j in xrange(i, N):
            if C[minj][1] > C[j][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C def selectionSort(C, N):
    for i in xrange(N):
        minj = i
        for j in xrange(i, N):
            if C[minj][1] > C[j][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C selectionSort def main():
    N = input()
    cards = raw_input().split()
    bubble = bubbleSort(cards[:], N)
    selection = selectionSort(cards[:], N)
    print ' '.join(bubble)
    print 'Stable' if isStable(cards, bubble, N) else 'Not stable'
    print ' '.join(selection)
    print 'Stable' if isStable(cards, selection, N) else 'Not stable' def main():
    N = input()
    cards = raw_input().split()
    bubble = bubbleSort(cards[:], N)
    selection = selectionSort(cards[:], N)
    print ' '.join(bubble)
    print 'Stable' if isStable(cards, bubble, N) else 'Not stable'
    print ' '.join(selection)
    print 'Stable' if isStable(cards, selection, N) else 'Not stable' main
# coding: utf-8

def bubbleSort(C, N):
    for i in xrange(N):
        for j in xrange(N-1, i, -1):
            if C[j-1][1] > C[j][1]:
                C[j], C[j-1] = C[j-1], C[j]
    return C

def selectionSort(C, N):
    for i in xrange(N):
        minj = i
        for j in xrange(i, N):
            if C[minj][1] > C[j][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C

def isStable(in_, out_, N):
    for i in xrange(N):
        for j in xrange(i + 1, N):
            for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
    return True

def main():
    N = input()
    cards = raw_input().split()
    bubble = bubbleSort(cards[:], N)
    selection = selectionSort(cards[:], N)
    print ' '.join(bubble)
    print 'Stable' if isStable(cards, bubble, N) else 'Not stable'
    print ' '.join(selection)
    print 'Stable' if isStable(cards, selection, N) else 'Not stable'



if __name__ == '__main__':
    main()