Problem:
Selection Sort Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A)
1 for i = 0 to A.length-1
2     mini = i
3     for j = i to A.length-1
4         if A[j] < A[mini]
5             mini = j
6     swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini. Input The first line of the input includes an integer N , the number of elements in the sequence. In the second line, N elements of the sequence are given separated by space characters. Output The output consists of 2 lines. In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. In the second line, please print the number of swap operations. Constraints 1 ≤ N ≤ 100 Sample Input 1 6
5 6 4 2 1 3 Sample Output 1 1 2 3 4 5 6
4 Sample Input 2 6
5 2 4 6 1 3 Sample Output 2 1 2 3 4 5 6
3

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
nums = [int(_) for _ in stdin.readline().rstrip().split()]

def select_sort(a, n):
    count = 0
    for i in range(n):
        mini = i
        for j in range(i, n):
            if a[j] < a[mini]:
                mini = j
        if mini != i:
            count += 1
        a[i], a[mini] = a[mini], a[i]
    return a, count

ret, count = select_sort(nums, N)
print(*ret)
print(count)

Solution (Python):
if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    cnt = 0
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if A[j] < A[minj]:
                minj = j
        if minj != i:
            A[minj], A[i] = A[i], A[minj]
            cnt += 1
    for x in A:
        print x,
    print
    print cnt

Solution (Python):
def show(nums):
    print(' '.join(map(str, nums)))    


def selection_sort(nums, n):
    count = 0
    for i in range(n):
        minj = i
        for j in range(i, n):
            if nums[j] < nums[minj]:
                minj = j
        v = nums[i]
        nums[i] = nums[minj]
        nums[minj] = v
        if i != minj:
            count += 1
    show(nums)
    print(count)

    
n = int(input())
nums = list(map(int, input().split()))
selection_sort(nums, n)

Solution (Python):
n = int(input())
array =list(map(int, input().split()))

min_index = 0
count = 0
for i in range(n):
    min_index = i
    for j in range(i+1, n):
        if array[min_index] > array[j]:
            min_index = j
    if array[i] != array[min_index]:
        array[i], array[min_index] = array[min_index], array[i]
        count += 1
print(' '.join(map(str, array)))
print(count)

Solution (Python):
"""


 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())


 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  


a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n= int(sys.stdin.readline())
    l= list(map(int, sys.stdin.readline().split()))
    c=0
    for i in range(n):
        minj=i
        for j in range(i,n):
            if l[j] < l[minj]:
                minj=j
        if i!=minj:
            c+=1
            temp=l[minj]
            l[minj]=l[i]
            l[i]=temp
    print(*l)
    print(c)

Solution (Python):
def p(a):
    for i in a[:-1]:
        print(i,end=' ')
    print(a[-1])


def selection_sort(a):
    cnt = 0
    for i in range(len(a)-1):
        fl = 0
        min = i
        for j in range(i+1,len(a)):
            if a[j]<a[min]:
                fl=1
                min = j
        cnt+=fl
        tmp = a[min]
        a[min] = a[i]
        a[i] = tmp
    p(a)
    print(cnt)


n = int(input())
l = list(map(int,input().split()))
selection_sort(l)

Solution (Python):
def hyoji(l):
    for i in range(len(l)):
        if i != len(l)-1:
            print(l[i], end = ' ')
        else:
            print(l[i])

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

c = 0
for j in range(len(A)):
    min_n = j
    for k in range(j + 1, len(A)):
        if A[k] < A[min_n]:
            min_n = k
    if min_n != j:
        A[j], A[min_n] = A[min_n], A[j]
        c += 1
hyoji(A)
print(c)

Solution (Python):
def selectionSort(A, N):
  cnt = 0
  for i in range(0,N):
    minj  = i
    for j in range(i, N):
      if A[j] < A[minj]:
        minj = j
    cnt = cnt + int(i != minj)
    A[i], A[minj] = A[minj], A[i]
  return cnt


N = int(input())
A = [int(i) for i in input().split()]
cnt = selectionSort(A, N)

for i in range(N):
  if i != 0:
    print(" ", end ="")
  print(A[i], end = "")
  
  
print()
print(cnt)

Solution (Python):
def main():
    n=int(input())
    a=list(map(int,input().split()))
    cnt=0
    for i in range(n-1):
        id=i
        mini=a[i]
        ch=False
        for j in range(i,n):
            if mini>a[j]:
                mini=a[j]
                id=j
                ch=True
        if ch:
            a[i],a[id]=a[id],a[i]
            cnt+=1
    print(*a)
    print(cnt)

main()

Solution (Python):
def print_format(N,input_list,count):
    for i in range(N):
        if i != N-1:
            print(input_list[i],end=" ")
        else:
            print(input_list[i])
    print(count)

def selection_sort(N,input_list):
    swap_count = 0
    for i in range(N):
        minj = i
        for j in range(i,N):
            if input_list[j] < input_list[minj]:
                minj = j
        if i != minj:
            swap_count += 1
        input_list[i],input_list[minj] = input_list[minj],input_list[i]
    return input_list,swap_count

def main():
    N = int(input())
    input_list = [int(i) for i in input().split()]
    input_list,count = selection_sort(N,input_list)
    print_format(N,input_list,count)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
numchange = 0

for i in range(n):
    minj = i
    for j in range(i, n):
        if A[j] < A[minj]:
            minj = j
    if A[i] != A[minj]:
        tmp = A[i]
        A[i] = A[minj]
        A[minj] = tmp
        numchange += 1
        
print(str(A).replace(',', '')[1:-1])
print(numchange)

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
cnt = 0
for i in range(N):
    minj = i
    for j in range(i,N):
        if As[j] < As[minj]:
            minj = j
    if minj != i:
        tmp = As[i]
        As[i] = As[minj]
        As[minj] = tmp
        cnt += 1
    
print(" ".join([str(a) for a in As]))
print(cnt)

Solution (Python):



def selectionSort(A):
    count = 0
    swap = False
    for i in range(len(A)):
        minj = i
        for j in range(i+1, len(A)):
            if A[j] < A[minj]:
                minj = j
                swap = True
        if swap:
            A[i], A[minj] = A[minj], A[i]
            count += 1
            swap = False
    
    print(" ".join(list(map(str, A))))
    print(count)

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

selectionSort(A)

Solution (Python):
length = int(input())
List = list(map(int, input().split()))

minimum = List[0]
count = 0

for i in range(length):
    minj = i
    for j in range(i,length):
        if List[j] < List[minj]:
            minj = j
    if List[minj] != List[i]:
        minimum = List[minj]
        List[minj] = List[i]
        List[i] = minimum
        count += 1

print(*List)
print(count)

Solution (Python):



n = int(input())
a = list(map(int, input().split()))
count = 0

for i1 in range(n):
    mini2 = i1
    for i2 in range(len(a[i1:])):
        i2 += i1
        if a[i2] < a[mini2]:
            mini2 = i2
    if i1 != mini2:
        temp = a[i1]
        a[i1] = a[mini2]
        a[mini2] = temp
        count +=1

print(a[0], end="")
for i in a[1:]:
    print(" {}".format(i),end="")

print("\n{}".format(count))

Solution (Python):
def selectionSort(A, n):
    cnt = 0
    for i in range(n):
        minj = i
        for j in range(i, n):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            cnt += 1
    print(*A)
    print(cnt)


n = int(input())
A = list(map(int, input().split()))
selectionSort(A, n)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
switch=0
for i in range(n-1):
    minj=i
    for j in range(i+1,n):
        if a[j]<a[minj]:
            minj=j
    if a[i]!=a[minj]:
        switch+=1
    a[i],a[minj]=a[minj],a[i]

for i in range(n-1):
    print(a[i],end=" ")
print(a[n-1])
print(switch)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

cnt = 0

for i in range(N):
    flag = 0
    min_j = i
    for j in range(i, N):
        if A[j] < A[min_j]:
            min_j = j
            flag = 1

    if flag:
        A[i], A[min_j] = A[min_j], A[i]
        cnt += 1

print(*A)
print(cnt)

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))

swap_count = 0
for i in range(0, n):
    mini = i
    for j in range(i, n):
        if a_list[j] < a_list[mini]:
            mini = j
    if i != mini:
        temp = a_list[i]
        a_list[i] = a_list[mini]
        a_list[mini] = temp
        swap_count = swap_count + 1

print(' '.join(map(str, a_list)))
print(swap_count)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
count = 0

for i in range(n-1):
    frag = 0
    minj = i
    for j in range(i+1,n):
        if A[minj] > A[j]:
            minj = j
            frag = 1

    if frag:
        v = A[minj]
        A[minj] = A[i]
        A[i] = v
        count += 1

print(' '.join(map(str, A)))
print(str(count))

Solution (Python):


N=int(input())
L=input().split( )
A=[int(L[i]) for i in range(N)]
c=0
for i in range(N):
    minj=i
    j=i
    while j<N:
        if A[j]<A[minj]:
            minj=j
        j+=1
    temp=A[i]
    A[i]=A[minj]
    A[minj]=temp
    
    
    if i!=minj:
        c+=1
for j in range(N):
    if j<N-1:
        print(A[j],end=" ")
    else:
        print(A[j])
print(c)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
counter = 0
for i in range(n):
  minj = i
  for j in range(i,n):
    if a[j] < a[minj]:
      minj = j
  if i != minj:
    counter += 1
    temp = a[i]
    a[i] = a[minj]
    a[minj] = temp
print(" ".join(map(str,a)))
print(counter)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
counter=0
for i in range(n):
    minj=i
    for j in range(i,n):
        if l[j]<l[minj]:
            minj=j
    if i !=minj:
        l[i],l[minj]=l[minj],l[i]
        counter+=1
for i in range(n):
    if i!=n-1:
        print(l[i],end=' ')
    else:
        print(l[i])
print(counter)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

def pr(list):
    n = len(list)
    for i in range(n):
        if i < n-1:
            print(list[i],end=" ")
        else:
            print(list[i],end="\n")

def sort():
    swap = 0
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            temp = A[i]
            A[i] = A[minj]
            A[minj] = temp
            swap += 1
    pr(A)
    print(swap)

sort()

Solution (Python):
n=int(input())
da=list(map(int,input().split()))
chco=0
for i in range(n):
    minj=i
    for j in range(i,n):
        if da[j]<da[minj]:
            minj=j
    if i!=minj:
        x=da[i]
        da[i]=da[minj]
        da[minj]=x
        chco+=1
for i in range(n):
    if i==n-1:
        print(da[i])
    else:
        print(da[i],end=' ')
print(chco)

Solution (Python):
def selectionSort(A):
    cnt = 0

    for i in range(len(A)):
        minj = i

        for j in range(i + 1, len(A)):
            if A[j] < A[minj]:
                minj = j

        if minj != i:
            A[i], A[minj] = A[minj], A[i]

            cnt += 1

    return A, cnt


N = int(input())
A = list(map(int, input().split()))

A_sorted, cnt = selectionSort(A)

print(*A_sorted)
print(cnt)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

count = 0

for i in range(N):
    minj = i
    for j in range(i+1, N):
        if a[minj]>a[j]:
            minj = j
    if a[i]!=a[minj]:
        a[i], a[minj] = a[minj], a[i]
        count += 1
print(' '.join(map(str, a)))
print(count)

Solution (Python):
if __name__ == '__main__':
	n = int(input())
	num = [int(i) for i in input().split()]
	count=0
	for i in range(n):
		mini = i
		for j in range(i,n):
			if num[j] < num[mini]:
				mini = j
		num[i],num[mini] = num[mini],num[i]
		if i != mini:
			count += 1
	for i in range(n):
		if i != n-1:
			print("%d" % (num[i]),end=" ")
		else:
			print("%d" % (num[i]))
	print(count)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
counter = 0
for i in range(0, N):
    minj = i
    for j in range(i, N):
        if A[j]<A[minj]:
            minj = j
    if i!=minj:
        counter += 1
        A[i], A[minj] = A[minj], A[i]   
print(' '.join(map(str, A)))
print(counter)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

minv = A[0]
sw = 0
for i in range(N):
    minv = min(A[i:])
    mini = A[i:].index(minv) + i
    if A[i] > minv:
        temp = A[i]
        A[i] = minv
        A[mini] = temp
        sw += 1

print(*A)
print(sw)

Solution (Python):
num = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(num-1):
    min_j = i
    for j in range(i+1, num):
        if A[min_j] > A[j]:
            min_j = j
    if min_j != i:
        a = A[i]
        A[i] = A[min_j]
        A[min_j] = a
        count += 1
A_str = [str(k) for k in A]
print(' '.join(A_str))
print(count)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(n):
    mini = i
    for j in range(i,n):
        if a[j]<a[mini]:
            mini = j
    key = a[mini]
    a[mini] = a[i]
    a[i] = key
    if mini!=i:count += 1

string = ''
for s_val in a[:-1]:
    string += str(s_val) + ' '
string += str(a[-1])
print(string)
print(count)

Solution (Python):

n = int(input())
a = [int(i) for i in input().split()]
cnt = 0
for ni in range(n):
  mini = ni
  for ii in range(ni,n):
    if a[ii] < a[mini]:
      mini = ii
  if mini != ni:
    cnt += 1
    a[ni], a[mini] = a[mini], a[ni]
print(" ".join([str(i) for i in a]))
print(cnt)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

def selectionSort(A, N):
    counter = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            counter += 1
        A[i], A[minj] = A[minj], A[i]
        i += 1

    print(" ".join(map(str, A)), counter, sep="\n")
selectionSort(A, N)

Solution (Python):
N = int(input())
a = list(map(int, input().strip().split()))
rel = 0
counter = 0
for i in range(0, N):
    minj = i
    for j in range(i+1,N):
        if(a[j]<a[minj]):
            minj = j
            rel += 1
    a[i],a[minj]=a[minj],a[i]
    if(rel>0):
      counter += 1
    rel = 0
print(*a)
print(counter)

Solution (Python):
def lP(l: list) -> None:
    for i in range(len(l)-1):
        print(l[i], end = ' ')
    print(l[len(l)-1])

N = int(input())
l = list(map(int, input().split()))
sum = 0

for i in range(N):
    minI = i
    for j in range(i+1, N):
        if l[minI] > l[j]:
            minI = j
    if i != minI:
        l[i], l[minI] = l[minI], l[i]
        sum += 1
lP(l)
print(sum)

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
ans=0
for i in range(N):
    minj=i
    for j in range(i,N):
        if A[j]<A[minj]:
            minj=j
    if i!=minj:
        A[i],A[minj]=A[minj],A[i]
        ans+=1
print(" ".join([str(i) for i in A]))
print(ans)

Solution (Python):
n = int(input())
s = [int(x) for x in input().split()]

cnt = 0
for i in range(len(s)):
    mini = i
    for j in range(i,len(s)):
        if(s[j] < s[mini]):
            mini = j
    
    if(i != mini):

        v = s[i]
        s[i] = s[mini]
        s[mini] = v
        cnt += 1


    
print(" ".join(map(str,s)))
print(cnt)

Solution (Python):
N = int(input())
list = list(input().split())

count = 0
for i in range(N):
  minj = i
  for j in range(i, N):
    if int(list[j]) < int(list[minj]):
      minj = j

  tmp = list[i]
  list[i] = list[minj]
  list[minj] = tmp
  if minj != i: count += 1
print(' '.join(list))
print(count)

Solution (Python):
num = int(input())
x = list(map(int, input().split()))
n = 0
for i in range(num):
    min_j = i
    for j in range(i, num):
        if x[min_j] > x[j]:
            min_j = j
    if min_j != i:
        x[i], x[min_j] = x[min_j], x[i]
        n += 1
print(' '.join([str(s) for s in x]))
print(n)

Solution (Python):
n=int(input())
cnt=0
num=list(map(int,input().split()))

for i in range(len(num)):
	min=i
	for j in range(i,len(num)):
		if num[j]<num[min]:
			min=j
	if num[i]>num[min]:
		num[i],num[min]=num[min],num[i]
		cnt+=1
print(' '.join(list(map(str,num))))
print(cnt)

Solution (Python):
n = int(input())
data = list(map(int, input().split()))
counter = 0
for i in range(n):
    num_min = float('inf')
    num_index = i
    for j in range(i, n):
        if data[j] < num_min:
            num_min = data[j]
            num_index = j
    if data[i] != data[num_index]:
        data[i], data[num_index] = data[num_index], data[i]
        counter += 1
print(*data)
print(counter)

Solution (Python):
def show(nums):
    for i in range(len(nums)):
        if i != len(nums)-1:
            print(nums[i],end=' ')
        else:
            print(nums[i])

N = int(input())
A = list(map(int,input().split()))
count = 0

for i in range(N):
    minj = i
    for j in range(i,N):
        if A[j] < A[minj]:
            minj = j
    tmp = A[i]
    A[i] = A[minj]
    A[minj] = tmp
    if i != minj:
        count += 1

show(A)
print(count)

Solution (Python):
def selection_sort(A, N):
	cnt = 0
	for i in range(N):
		minj = i
		for j in range(i, N):
			if A[j] < A[minj]:
				minj = j
		A[i], A[minj] = A[minj], A[i]
		if minj!=i:
			cnt += 1

	return A, cnt

N = int(input())
A = list(map(int, input().split()))

A, cnt = selection_sort(A, N)
print(' '.join(map(str, A)))
print(cnt)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
count = 0

for i in range(n):
    minA = i
    flag = False
    for j in range(i, n):
        if A[j] < A[minA]:
            minA = j
            flag = True
    
    if flag:
        v = A[i]
        A[i] = A[minA]
        A[minA] = v
        count += 1


print(" ".join(map(str, A)))
print(count)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
t = 0

for i in range(n):
    minj = i
    for j in range(i, n):
        if a[j] < a[minj]:
            minj = j
    a[i], a[minj] = a[minj], a[i]
    if i != minj:
        t += 1

print(' '.join(map(str, a)))
print(t)

Solution (Python):
n = int(input())
nums = list(map(int, input().split()))
count = 0
for i in range(n):
    mini = i
    for j in range(i, n):
        if nums[j] < nums[mini]:
            mini = j
    if mini != i:
        count += 1
        nums[i], nums[mini] = nums[mini], nums[i]
for i in range(n-1):
    print(nums[i], end = ' ')
print(nums[n-1])
print(count)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
change_A = 0

for i in range(N):
    mini = i
    for j in range(i+1,N):
        if A[j] < A[mini]:
            mini = j
    
    if mini != i:
        v = A[i]
        A[i] = A[mini]
        A[mini] = v
        change_A += 1

for i in range(N):
    if i == N-1:
        print(A[i])
    else:
        print(A[i],end=' ')
        
print(change_A)

Solution (Python):
n = int(input())
*A, = map(int, input().split())
ans = 0

for i in range(n):
  minj = i
  for j in range(i, n):
    if A[j] < A[minj]:
      minj = j
  if i != minj:
    A[i], A[minj] = A[minj], A[i]
    ans += 1

print(*A)
print(ans)

Solution (Python):
def selectionSort(A,N):
    swapCount = 0
    for i in range(N):
        minj = A[i]
        indexj = i
        for j in range(i,N):
            if A[j] < minj:
                minj = A[j]
                indexj = j
        if indexj != i:
            A[indexj] = A[i]
            A[i] = minj
            swapCount += 1
    str = ""
    for k in range(N):
        str += "{} ".format(A[k])
    print(str[:len(str)-1])
    print(swapCount)

if __name__ == '__main__':
    N = int(input())
    A = [int(_) for _ in input().split()]

    selectionSort(A,N)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
c = 0

for i in range(len(A)):
    minA = i
    for j in range(i, len(A)):
        if A[j] < A[minA]:
            minA = j

    if i != minA:
        p = A[i]
        A[i] = A[minA]
        A[minA] = p
        c += 1

print(" ".join(map(str, A)))
print(c)

Solution (Python):
import sys






"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    
    r, e, p = range, enumerate, print
    ip = IP()
    id = Idea()
    mod = 10 ** 9 + 7

    """この下から書いてね"""
    n = ip.I()
    a = ip.IL()
    flag = True
    ans = 0
    for i in r(n):
        flag = False
        minj = i
        for j in r(i, n):
            if a[j] < a[minj]:
                minj = j
                flag = True
        if flag:
            a[i], a[minj] = a[minj], a[i]
            ans += 1
        
    p(*a)
    p(ans)


main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in range(n-1):
    min = a[i]
    ch = i
    for j in range(i+1,n):
        if min > a[j]:
            min = a[j]
            ch = j
    if i != ch:
        a[i], a[ch] = a[ch], a[i]
        c += 1
print(" ".join(map(str,a)))
print(c)

Solution (Python):
def selection_sort(A, N):
    count = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            count += 1
    return count


N = int(input())
A = list(map(int, input().split()))
count = selection_sort(A, N)

print(" ".join(list(map(str, A))))
print(count)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(N):
    minj = i
    for j in range(i, N):
        if A[j] < A[minj] :
            minj = j
    if minj != i:
        count += 1
    A[i], A[minj] = A[minj], A[i]
        
print(*A)
print(count)

Solution (Python):
n=int(input())
ns=list(map(int,input().split()))
ans=0
for i in range(n):
    minj=i
    for j in range(i,n):
        if(ns[j]<ns[minj]):
            minj=j
    if i!=minj:
        ans+=1
        k=ns[i]
        ns[i]=ns[minj]
        ns[minj]=k
 
for i in range(n):
    if(i!=n-1):
        print(ns[i],end=' ')
print(ns[n-1])
print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
cnt = 0
for i in range(n):
    minj = i
    for j in range(i,n):
        if a[j] < a[minj]:
            minj = j
    if i != minj:
        a[i], a[minj] = a[minj], a[i]
        cnt += 1
print(' '.join([str(i) for i in a]))
print(cnt)

Solution (Python):
def selectionSort(A, N):
    count = 0
    for i in range(0, N):
        minj = i
        flag = 0
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
                flag = 1
        A[i], A[minj] = A[minj], A[i]
        if flag:
            count += 1
    return A, count

N = int(input())
A = list(map(int, input().split()))
A, count = selectionSort(A, N)
print(*A)
print(count)

Solution (Python):
def readInt():
  return int(input())


def readInts():
  return [int(i) for i in input().split()]


N = readInt()
AS = readInts()

cnt = 0

for i in range(N):
    minj = i
    for j in range(i, N):
        if AS[j] < AS[minj]:
            minj = j
    if i != minj:
        cnt += 1
        AS[i], AS[minj] = AS[minj], AS[i]

print(*AS)
print(cnt)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
    minj = i
    for j in range(i, n):
        if a[j] < a[minj]:
            minj = j
    if a[i] != a[minj]:
        cnt += 1
    a[i], a[minj] = a[minj], a[i]
print(' '.join(map(str, a)))
print(cnt)

Solution (Python):
time = int(input())
nums = list(map(int,input().split(" ")))
count = 0

for i in range(time):
    top = nums[i]
    mi = min(nums[i:])
    if top > mi:
        count += 1
        a = top
        
        
        tmpIndex = nums[i:].index(mi) + i
        nums[i] = mi
        nums[tmpIndex] = a

print(' '.join(map(str,nums)))
print(count)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
count = 0
for i in range(n):
    minj = i
    for j in range(i,n):
        if a[j] < a[minj]:
            minj = j
    a[i],a[minj] = a[minj],a[i]
    if i != minj:
        count += 1

print(*a)
print(count)

Solution (Python):
def selective_sort(A):
    global N
    i = 0 
    swap = 0
    while i < N-1:
        mini = i 
        for j in range(i+1, N):
            if A[j] < A[mini]:
                mini = j
        if mini != i:
            A[i],A[mini] = A[mini],A[i]
            swap += 1
        i += 1
    return swap 

N = int(input())
A = list(map(int, input().split()))
swap = selective_sort(A)
print(' '.join(list(map(str, A))))
print(swap)

Solution (Python):
n,*a=map(int,open(0).read().split())
c=0
for i in range(n):
    minj=i
    for j in range(i,n):
        if a[j]<a[minj]:
            minj=j
    if a[i]!=a[minj]:
        c+=1
    a[i],a[minj]=a[minj],a[i]
print(*a)
print(c)

Solution (Python):

n = int(input())
*v, = map(int, input().split())
c = 0
for i in range(n):
    mi = i
    for j in range(i, n):
        if v[j] < v[mi]:
            mi = j
    if mi != i:
        c += 1
    v[i], v[mi] = v[mi], v[i]


print(" ".join([str(_v) for _v in v]))
print(c)

Solution (Python):
n = int(input())
nums = [int(num) for num in input().split(" ")]
result_string = ""
change_times = 0

for i in range(n):
    minj = i
    for j in range(i, n):
        if nums[j] < nums[minj]:
            minj = j
    if minj != i:
        tmp = nums[minj]
        nums[minj] = nums[i]
        nums[i] = tmp
        change_times += 1
    if result_string == "":
        result_string += str(nums[i])
    else:
        result_string += " "
        result_string += str(nums[i])
            
print(result_string)
print(change_times)

Solution (Python):
factor = int(input())
numbers = list(map(int,input().split()))

def selectionsort(array,n):
    counter = 0
    for i in range(len(array)):
        minj = i
        for j in range(i,len(array)):
            if array[j] < array[minj]:
                minj = j
        array[minj],array[i] = array[i],array[minj]
        if minj != i :
            counter += 1
    return counter

repetition = selectionsort(numbers,factor)
print(" ".join(list(map(str,numbers))))
print(repetition)

Solution (Python):
N = int(input())
A = input()
B = A.split()
total = 0
for i in range(N) :
    mini = int(i)
    for j in range(i, N) :
        if int(B[j]) < int(B[mini]) :
            mini = int(j)
    if mini != int(i) :
        B[i], B[mini] = B[mini], B[i]
        total += 1
print(" ".join(B))
print(total)

Solution (Python):
def swap(a, i, j):
    
    k = a[j]
    a[j] = a[i]
    a[i] = k


def selectionSort(a, n):
    sw = 0
    for i in range(n):
        minj = i
        for j in range(i,n):
            if a[j] < a[minj]:
                minj = j
        if i != minj:
            sw += 1
        swap(a,i,minj)
    print(' '.join(list(map(str, a))))
    print(sw)


n = int(input())
a = list(map(int, input().split()))
selectionSort(a, n)

Solution (Python):
n = int(input())
cards = list(map(int,input().split()))
cnt = 0
for i in range(n):
    minj = i
    for j in range(i,n):
        if cards[minj] > cards[j]:
            minj = j
    if i != minj:
        cnt += 1
    cards[i], cards[minj] = cards[minj], cards[i]


print(*cards)
print(cnt)