# -*- coding:utf-8 -*-

import copy

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

def selection_sort(num_list):
    for i in range(len(num_list)):
        mini = i
        for j in range(i, len(num_list)):
            if num_list[j][1] < num_list[mini][1]:
                mini = j
        num_list[i], num_list[mini] = num_list[mini], num_list[i]
    return num_list

def is_stable(before_sort, after_sort):
    current_num = 0
    same_number_card = list()
    for num in after_sort:
        if current_num == int(num[1]):
            for same_card in same_number_card:
                if before_sort.index(same_card) > before_sort.index(num):
                    return False
            same_number_card.append(num)
        else:
            current_num = int(num[1])
            same_number_card = [num,]
    return True

def show_list(list):
    i = 0;
    while(i < len(list)-1):
        print(list[i], end=" ")
        i = i + 1
    print(list[i])

def show_stable(flag):
    if flag:
        print('Stable')
    else:
        print('Not stable')

num = int(input())
input_card = [x for i, x in enumerate(input().split()) if i < num]
bubble_sort_card = bubble_sort(copy.deepcopy(input_card))
show_list(bubble_sort_card)
show_stable(is_stable(input_card, bubble_sort_card))
selection_sort_card = selection_sort(copy.deepcopy(input_card))
show_list(selection_sort_card)
show_stable(is_stable(input_card, selection_sort_card)) import copy copy def bubble_sort(num_list):
    for i in range(len(num_list)):
        for j in range(len(num_list)-1, i , -1):
            if num_list[j][1] < num_list[j-1][1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
    return num_list bubble_sort for i in range(len(num_list)):
        for j in range(len(num_list)-1, i , -1):
            if num_list[j][1] < num_list[j-1][1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
     i range(len(num_list)) range len(num_list) len num_list for j in range(len(num_list)-1, i , -1):
            if num_list[j][1] < num_list[j-1][1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
     j range(len(num_list)-1, i , -1) range len(num_list)-1 len(num_list) len num_list 1 i -1 if num_list[j][1] < num_list[j-1][1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
     num_list[j][1] < num_list[j-1][1] num_list[j][1] [j] num_list j 1 num_list[j-1][1] [j-1] num_list j-1 j 1 1 num_list[j], num_list[j-1] = num_list[j-1], num_list[j] num_list[j] num_list j num_list[j-1] num_list j-1 j 1 num_list[j-1] num_list j-1 j 1 num_list[j] num_list j return num_list num_list num_list num_list def selection_sort(num_list):
    for i in range(len(num_list)):
        mini = i
        for j in range(i, len(num_list)):
            if num_list[j][1] < num_list[mini][1]:
                mini = j
        num_list[i], num_list[mini] = num_list[mini], num_list[i]
    return num_list selection_sort for i in range(len(num_list)):
        mini = i
        for j in range(i, len(num_list)):
            if num_list[j][1] < num_list[mini][1]:
                mini = j
        num_list[i], num_list[mini] = num_list[mini], num_list[i]
     i range(len(num_list)) range len(num_list) len num_list mini = i mini i for j in range(i, len(num_list)):
            if num_list[j][1] < num_list[mini][1]:
                mini = j
         j range(i, len(num_list)) range i len(num_list) len num_list if num_list[j][1] < num_list[mini][1]:
                mini = j
         num_list[j][1] < num_list[mini][1] num_list[j][1] [j] num_list j 1 num_list[mini][1] [mini] num_list mini 1 mini = j mini j num_list[i], num_list[mini] = num_list[mini], num_list[i] num_list[i] num_list i num_list[mini] num_list mini num_list[mini] num_list mini num_list[i] num_list i return num_list num_list num_list num_list def is_stable(before_sort, after_sort):
    current_num = 0
    same_number_card = list()
    for num in after_sort:
        if current_num == int(num[1]):
            for same_card in same_number_card:
                if before_sort.index(same_card) > before_sort.index(num):
                    return False
            same_number_card.append(num)
        else:
            current_num = int(num[1])
            same_number_card = [num,]
    return True is_stable current_num = 0 current_num 0 same_number_card = list() same_number_card list() list for num in after_sort:
        if current_num == int(num[1]):
            for same_card in same_number_card:
                if before_sort.index(same_card) > before_sort.index(num):
                    return False
            same_number_card.append(num)
        else:
            current_num = int(num[1])
            same_number_card = [num,]
     num after_sort if current_num == int(num[1]):
            for same_card in same_number_card:
                if before_sort.index(same_card) > before_sort.index(num):
                    return False
            same_number_card.append(num)
        else:
            current_num = int(num[1])
            same_number_card = [num,]
     current_num == int(num[1]) current_num int(num[1]) int num[1] num 1 for same_card in same_number_card:
                if before_sort.index(same_card) > before_sort.index(num):
                    return False
             same_card same_number_card if before_sort.index(same_card) > before_sort.index(num):
                    return False
             before_sort.index(same_card) > before_sort.index(num) before_sort.index(same_card) before_sort.index before_sort index same_card before_sort.index(num) before_sort.index before_sort index num return False False same_number_card.append(num) same_number_card.append same_number_card append num current_num = int(num[1]) current_num int(num[1]) int num[1] num 1 same_number_card = [num,] same_number_card [num,] num return True True before_sort before_sort after_sort after_sort def show_list(list):
    i = 0;
    while(i < len(list)-1):
        print(list[i], end=" ")
        i = i + 1
    print(list[i]) show_list i = 0 i 0 while(i < len(list)-1):
        print(list[i], end=" ")
        i = i + 1
     i < len(list)-1 i len(list)-1 len(list) len list 1 print(list[i], end=" ") print list[i] list i end=" " end " " i = i + 1 i i + 1 i 1 print(list[i]) print list[i] list i list list def show_stable(flag):
    if flag:
        print('Stable')
    else:
        print('Not stable') show_stable if flag:
        print('Stable')
    else:
        print('Not stable') flag print('Stable') print 'Stable' print('Not stable') print 'Not stable' flag flag num = int(input()) num int(input()) int input() input x for i, x in enumerate(input().split()) if i < num for i, x in enumerate(input().split()) if i < num i x enumerate(input().split()) enumerate input().split() ().split () input split i < num i num if i < num x input_card = [x for i, x in enumerate(input().split()) if i < num] input_card [x for i, x in enumerate(input().split()) if i < num] bubble_sort_card = bubble_sort(copy.deepcopy(input_card)) bubble_sort_card bubble_sort(copy.deepcopy(input_card)) bubble_sort copy.deepcopy(input_card) copy.deepcopy copy deepcopy input_card show_list(bubble_sort_card) show_list bubble_sort_card show_stable(is_stable(input_card, bubble_sort_card)) show_stable is_stable(input_card, bubble_sort_card) is_stable input_card bubble_sort_card selection_sort_card = selection_sort(copy.deepcopy(input_card)) selection_sort_card selection_sort(copy.deepcopy(input_card)) selection_sort copy.deepcopy(input_card) copy.deepcopy copy deepcopy input_card show_list(selection_sort_card) show_list selection_sort_card show_stable(is_stable(input_card, selection_sort_card)) show_stable is_stable(input_card, selection_sort_card) is_stable input_card selection_sort_card def is_stable(before_sort, after_sort):
    current_num = 0
    same_number_card = list()
    for num in after_sort:
        if current_num == int(num[1]):
            for same_card in same_number_card:
                if before_sort.index(same_card) > before_sort.index(num):
                    return False
            same_number_card.append(num)
        else:
            current_num = int(num[1])
            same_number_card = [num,]
    return True def is_stable(before_sort, after_sort):
    current_num = 0
    same_number_card = list()
    for num in after_sort:
        if current_num == int(num[1]):
            for same_card in same_number_card:
                if before_sort.index(same_card) > before_sort.index(num):
                    return False
            same_number_card.append(num)
        else:
            current_num = int(num[1])
            same_number_card = [num,]
    return True is_stable input_card = [x for i, x in enumerate(input().split()) if i < num] [x for i, x in enumerate(input().split()) if i < num] input_card num = int(input()) int(input()) num bubble_sort_card = bubble_sort(copy.deepcopy(input_card)) bubble_sort(copy.deepcopy(input_card)) bubble_sort_card def bubble_sort(num_list):
    for i in range(len(num_list)):
        for j in range(len(num_list)-1, i , -1):
            if num_list[j][1] < num_list[j-1][1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
    return num_list def bubble_sort(num_list):
    for i in range(len(num_list)):
        for j in range(len(num_list)-1, i , -1):
            if num_list[j][1] < num_list[j-1][1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
    return num_list bubble_sort def selection_sort(num_list):
    for i in range(len(num_list)):
        mini = i
        for j in range(i, len(num_list)):
            if num_list[j][1] < num_list[mini][1]:
                mini = j
        num_list[i], num_list[mini] = num_list[mini], num_list[i]
    return num_list def selection_sort(num_list):
    for i in range(len(num_list)):
        mini = i
        for j in range(i, len(num_list)):
            if num_list[j][1] < num_list[mini][1]:
                mini = j
        num_list[i], num_list[mini] = num_list[mini], num_list[i]
    return num_list selection_sort def show_list(list):
    i = 0;
    while(i < len(list)-1):
        print(list[i], end=" ")
        i = i + 1
    print(list[i]) def show_list(list):
    i = 0;
    while(i < len(list)-1):
        print(list[i], end=" ")
        i = i + 1
    print(list[i]) show_list def show_stable(flag):
    if flag:
        print('Stable')
    else:
        print('Not stable') def show_stable(flag):
    if flag:
        print('Stable')
    else:
        print('Not stable') show_stable selection_sort_card = selection_sort(copy.deepcopy(input_card)) selection_sort(copy.deepcopy(input_card)) selection_sort_card
# -*- coding:utf-8 -*-

import copy

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

def selection_sort(num_list):
    for i in range(len(num_list)):
        mini = i
        for j in range(i, len(num_list)):
            if num_list[j][1] < num_list[mini][1]:
                mini = j
        num_list[i], num_list[mini] = num_list[mini], num_list[i]
    return num_list

def is_stable(before_sort, after_sort):
    current_num = 0
    same_number_card = list()
    for num in after_sort:
        if current_num == int(num[1]):
            for same_card in same_number_card:
                if before_sort.index(same_card) > before_sort.index(num):
                    return False
            same_number_card.append(num)
        else:
            current_num = int(num[1])
            same_number_card = [num,]
    return True

def show_list(list):
    i = 0;
    while(i < len(list)-1):
        print(list[i], end=" ")
        i = i + 1
    print(list[i])

def show_stable(flag):
    if flag:
        print('Stable')
    else:
        print('Not stable')

num = int(input())
input_card = [x for i, x in enumerate(input().split()) if i < num]
bubble_sort_card = bubble_sort(copy.deepcopy(input_card))
show_list(bubble_sort_card)
show_stable(is_stable(input_card, bubble_sort_card))
selection_sort_card = selection_sort(copy.deepcopy(input_card))
show_list(selection_sort_card)
show_stable(is_stable(input_card, selection_sort_card))