if __FILE__ == $0
  while num = STDIN.gets.to_i
    tokens = STDIN.gets.chomp!.split
    b_result = Marshal.load(Marshal.dump(tokens))
    bubblesort(b_result)
    puts b_result.join(" ")
    puts "Stable"
    s_result = Marshal.load(Marshal.dump(tokens))
    selsort(s_result)
    puts s_result.join(" ")
    flag = true
    for i in 0..num-1
      if b_result[i] != s_result[i]
        flag = FALSE
      end
    end
    if flag
      puts "Stable"
    else
      puts "Not stable"
    end
  end
end