import copy
N = int(input())
bscs = [(int(c[-1]), c) for c in input().split(" ")]
sscs = copy.copy(bscs)
for i in range(N):
    j = N - 1
    while j > i:
        if bscs[j][0] < bscs[j - 1][0]:
            tmp = bscs[j]
            bscs[j] = bscs[j - 1]
            bscs[j - 1] = tmp
        j -= 1
print(" ".join([c[1] for c in bscs]))
print("Stable")
for i in range(N):
    minj = i
    for j in range(i, N):
        if sscs[j][0] < sscs[minj][0]:
            minj = j
    tmp = sscs[i]
    sscs[i] = sscs[minj]
    sscs[minj] = tmp
print(" ".join([c[1] for c in sscs]))
print("Stable" if bscs == sscs else "Not stable") import copy copy N = int(input()) N int(input()) int input() input (int(c[-1]), c) for c in input().split(" ") for c in input().split(" ") c input().split(" ") ().split () input split " " for c in input().split(" ") (int(c[-1]), c) int(c[-1]) int c[-1] c -1 c bscs = [(int(c[-1]), c) for c in input().split(" ")] bscs [(int(c[-1]), c) for c in input().split(" ")] sscs = copy.copy(bscs) sscs copy.copy(bscs) copy.copy copy copy bscs for i in range(N):
    j = N - 1
    while j > i:
        if bscs[j][0] < bscs[j - 1][0]:
            tmp = bscs[j]
            bscs[j] = bscs[j - 1]
            bscs[j - 1] = tmp
        j -= 1 i range(N) range N j = N - 1 j N - 1 N 1 while j > i:
        if bscs[j][0] < bscs[j - 1][0]:
            tmp = bscs[j]
            bscs[j] = bscs[j - 1]
            bscs[j - 1] = tmp
        j -= 1 j > i j i if bscs[j][0] < bscs[j - 1][0]:
            tmp = bscs[j]
            bscs[j] = bscs[j - 1]
            bscs[j - 1] = tmp
         bscs[j][0] < bscs[j - 1][0] bscs[j][0] [j] bscs j 0 bscs[j - 1][0] [j - 1] bscs j - 1 j 1 0 tmp = bscs[j] tmp bscs[j] bscs j bscs[j] = bscs[j - 1] bscs[j] bscs j bscs[j - 1] bscs j - 1 j 1 bscs[j - 1] = tmp bscs[j - 1] bscs j - 1 j 1 tmp j -= 1 j 1 c[1] for c in bscs for c in bscs c bscs for c in bscs c[1] c 1 print(" ".join([c[1] for c in bscs])) print " ".join([c[1] for c in bscs]) " ".join " " join [c[1] for c in bscs] print("Stable") print "Stable" for i in range(N):
    minj = i
    for j in range(i, N):
        if sscs[j][0] < sscs[minj][0]:
            minj = j
    tmp = sscs[i]
    sscs[i] = sscs[minj]
    sscs[minj] = tmp i range(N) range N minj = i minj i for j in range(i, N):
        if sscs[j][0] < sscs[minj][0]:
            minj = j
     j range(i, N) range i N if sscs[j][0] < sscs[minj][0]:
            minj = j
     sscs[j][0] < sscs[minj][0] sscs[j][0] [j] sscs j 0 sscs[minj][0] [minj] sscs minj 0 minj = j minj j tmp = sscs[i] tmp sscs[i] sscs i sscs[i] = sscs[minj] sscs[i] sscs i sscs[minj] sscs minj sscs[minj] = tmp sscs[minj] sscs minj tmp c[1] for c in sscs for c in sscs c sscs for c in sscs c[1] c 1 print(" ".join([c[1] for c in sscs])) print " ".join([c[1] for c in sscs]) " ".join " " join [c[1] for c in sscs] print("Stable" if bscs == sscs else "Not stable") print "Stable" if bscs == sscs else "Not stable" bscs == sscs bscs sscs "Stable" "Not stable" bscs = [(int(c[-1]), c) for c in input().split(" ")] [(int(c[-1]), c) for c in input().split(" ")] bscs tmp = bscs[j] bscs[j] tmp minj = j j minj j -= 1 1 j minj = i i minj tmp = sscs[i] sscs[i] tmp N = int(input()) int(input()) N sscs = copy.copy(bscs) copy.copy(bscs) sscs j = N - 1 N - 1 j
import copy
N = int(input())
bscs = [(int(c[-1]), c) for c in input().split(" ")]
sscs = copy.copy(bscs)
for i in range(N):
    j = N - 1
    while j > i:
        if bscs[j][0] < bscs[j - 1][0]:
            tmp = bscs[j]
            bscs[j] = bscs[j - 1]
            bscs[j - 1] = tmp
        j -= 1
print(" ".join([c[1] for c in bscs]))
print("Stable")
for i in range(N):
    minj = i
    for j in range(i, N):
        if sscs[j][0] < sscs[minj][0]:
            minj = j
    tmp = sscs[i]
    sscs[i] = sscs[minj]
    sscs[minj] = tmp
print(" ".join([c[1] for c in sscs]))
print("Stable" if bscs == sscs else "Not stable")