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):

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 i != minj:
        a[i], a[minj] = a[minj], a[i]
        cnt += 1
    
    
print(*a)
print(cnt)

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

Solution (Python):
list_size = input()                                                                                                                                                                                         
list_str = input()                                                                                                                                                                                          
val_list = list(map(int, list_str.split()))                                                                                                                                                                 
                                                                                                                                                                                                            
def where_is_the_first_lowest_val(List):                                                                                                                                                                    
    return List.index(min(List))                                                                                                                                                                            
                                                                                                                                                                                                            
def swap(idx_num, lowest_val_index, List):                                                                                                                                                                  
    val = List[idx_num]                                                                                                                                                                                     
    List[idx_num] = List[lowest_val_index + idx_num]                                                                                                                                                        
    List[lowest_val_index + idx_num] = val                                                                                                                                                                  
                                                                                                                                                                                                            
swap_num = 0                                                                                                                                                                                                
for idx_num in range(0, int(list_size) - 1):                                                                                                                                                                
    unsorted_list = val_list[idx_num : int(list_size)]                                                                                                                                                      
    lowest_val_index = where_is_the_first_lowest_val(unsorted_list)                                                                                                                                         
    if val_list[idx_num] != val_list[lowest_val_index + idx_num]: swap(idx_num, lowest_val_index, val_list) ; swap_num += 1                                                                                 
                                                                                                                                                                                                            
str_list = list(map(str, val_list))                                                                                                                                                                         
str_list = ','.join(str_list).replace(',', ' ')                                                                                                                                                             
print(str_list)                                                                                                                                                                                             
print(swap_num)

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
        if flag == 1:
            count += 1
        v = A[i]
        A[i] = A[minj]
        A[minj] = v

    return A, count

N = input()

line = raw_input()
line = line.strip().split()
line = map(lambda x: int(x), line)
a = selectionSort(line, N)

print(' '.join(map(lambda x: str(x), a[0])))
print(a[1])

Solution (Python):


def printA(a, n):
    for i in range(n):
        print(a[i],end="")
        if i < n - 1:
            print(" ", end="")
        else:
            print()

def selectionSort(a, n):
    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
    return count

n = int(input().rstrip())
a = list(map(int,input().rstrip().split()))
c = selectionSort(a, n)
printA(a, n)
print(c)

Solution (Python):
def selection_sort(A: list, N:int) -> list:
    """
    :A[N]: サイズがNの整数型配列。
    :i: 未ソートの部分の先頭を指すループ変数で、配列の先頭から末尾に向かって移動する。
    :minj: 各ループの処理でi 番目からN-1 番目までの要素で最小のものの位置。j 未ソートの部分から最小値の位置（minj）を探すためのループ変数。
    """
    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, b = A[i], A[minj]
            A[i], A[minj] = b, a
            count += 1

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

A, count = selection_sort(A, N)
print(*A)
print(count)

Solution (Python):
def selection_sort(array):
    N = len(array)
    exc_time = 0
    for i in range(N):
        min_index = i
        for j in range(i, N):
            if array[min_index] > array[j]:
                min_index = j
        if min_index != i:
            array[i], array[min_index] = array[min_index], array[i]
            exc_time += 1
    return exc_time
    
def putsarray(array):
    for i in range(len(array) - 1):
        print(array[i], end=' ')
    print(array[-1])

if __name__ == "__main__":
    N = int(input())
    array = input().split()
    array = [int(n) for n in array]
    exc = selection_sort(array)
    putsarray(array)
    print(exc)

Solution (Python):
def show(nums):
    for i in range(len(nums)):
        if i!=len(nums)-1:
            print(nums[i],end=' ')
        else:
            print(nums[i])
def selectionSort(A,N):
    count=0
    for i in range(N):
        minj = i
        for j in range(i+1,N):
            if A[j] < A[minj]:
                minj = j
        if A[i]>A[minj]:
            A[i],A[minj]=A[minj],A[i]
            count+=1
    show(A)
    print(count)
N = int(input())
A = list(map(int,input().split()))
selectionSort(A,N)

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 i!=minj:
        a[i],a[minj]=a[minj],a[i]
        count=count+1
print(" ".join(map(str,a)))
print(count)

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()))

counter = 0

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

show(A)
print(counter)

Solution (Python):
def selectionSort(A,N):
    '''list of int, int -> list of int
    return sorted list(selection sort)
    '''
    assert(len(A) == N)
    outA = A.copy()
    cnt = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if outA[j] < outA[minj]:
                minj = j
        outA[i], outA[minj] = outA[minj], outA[i]
        if i != minj:
            cnt += 1
    return outA, cnt
def printlist(L):
    for itm in L[:-1]:
        print(itm, end = ' ')
    print(L[-1])

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

Solution (Python):
num = int(input())

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

for i in range(0, num):
        minID = i
        for j in range(i, num):
                if A[j] < A[minID]:
                        minID = j
        if i != minID:
                A[i],  A[minID] = A[minID], A[i]
                count += 1

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

Solution (Python):
def selection_sort(A):
    count = 0
    for i in range(len(A)):
        minv = 101
        minj = -1
        for j in range(i, len(A)):
            if minv > A[j]:
                minv = A[j]
                minj = j
        if A[i] != A[minj]:
            A[i], A[minj] = A[minj], A[i]
            count += 1

    return count


n = int(input())
A = [int(x) for x in input().split()]

count = selection_sort(A)

print(' '.join([str(x) for x in A]))
print(count)

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

Solution (Python):
def selectionSort(a, n):
    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
    printArray(a)
    print(count)



def printArray(array):
    print(' '.join(map(str, array)))




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

selectionSort(a, n)

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

N = int(input())
A = list(map(int, input().split()))
A, t = selectionSort(A, N)
print(' '.join(map(str, A)), t, sep='\n')

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:
        A[i], A[minj] = A[minj], A[i]
        count += 1
print(*A)
print(count)

Solution (Python):
N = int(input())
I = list(map(int, input().split()))
cnt = 0
for i in range(N):
    min_index = i
    for j in range(i, N):
        if (I[j] < I[min_index]):
            min_index = j
    if (min_index != i):
        tmp = I[i]
        I[i] = I[min_index]
        I[min_index] = tmp
        cnt += 1

print(str(I).replace(',','').replace('[','').replace(']',''))
print(cnt)

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

for i in range(n):
    min=a[i]
    k=i
    for j in range((i+1),n):
        if min > a[j]:
            min=a[j]
            k=j
    if k!=i :
        a[i],a[k]=a[k],a[i]
        count+=1

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

Solution (Python):
def sort(A):
    global c
    c=0 
    for i in range(0,len(A)-1):
        selection(A,i)
        
    return A

def selection(A,i):
    global c
    min=i
    for j in range(i+1,len(A)):
        if A[min]>A[j]:
            min=j
            
            
    A[i],A[min]=A[min],A[i]
    if not A[i]==A[min]:
        c+=1
    
    
n=int(input())
A=list(map(int,input().split()))

sort(A)
print(' '.join(list(map(str,A))))
print(c)

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


n = int(input())
a = [int(i) for i in input().split()]
count = selectionSort(a, n)
print(" ".join(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 A[i] != A[minj]:
        count += 1
        A[i], A[minj] = A[minj], A[i]

print(*A)
print(count)

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

Solution (Python):

def showList(list1):
  for i in range(len(list1)):
    if(i<len(list1)-1):
      print(list1[i],end=' ')
    else:
      print(list1[i])
      
def selectionSort(seq):
  swapCount = 0
  for i in range(len(seq)):
    minIndex = i
    for j in range(i+1,len(seq)):
      if seq[minIndex]>seq[j]:
        minIndex = j
    if i!=minIndex:
      seq[i],seq[minIndex] = seq[minIndex],seq[i]
      swapCount+=1
  return swapCount

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

count = selectionSort(list1)
showList(list1)
print(count)

Solution (Python):
n = int(input())
s = list(map(int, input().strip().split(' ')))

count = 0

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

for i in range(n):
    if i != n - 1:
        print(s[i], end = ' ')
    else:
        print(s[i])

print(count)

Solution (Python):
def selectionSort(A, N): 
    counter = 0
    for i in range(0,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:
            counter += 1
    return A, counter

if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    a, num = selectionSort(a, N)
    for i in range(len(a)):
        if i != len(a)-1:
            print(a[i], end=" ")
        else:
            print(a[i])
    print(num)

Solution (Python):
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

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

    if i != minj:
        A[i], A[minj] = A[minj], A[i]
        count += 1

print(*A)
print(count)

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

def selectionSort(A, N):
    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
    return count

c = selectionSort(A, N)
for i in range(len(A)):
    if i != len(A) - 1:
        print(A[i], end=" ")
    else:
        print(A[i])
print(c)

Solution (Python):
def printer(A):
    ret = str(A[0])
    for i in range(1, len(A)):
        ret += " " + str(A[i])
    print(ret)
    return True


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

ans = 0
for i in range(n):
    minj = i
    for j in range(i, n):
        if A[minj] > A[j]:
            minj = j
    if i != minj:
        ans += 1
        tmp = A[i]
        A[i] = A[minj]
        A[minj] = tmp
printer(A)
print(ans)

Solution (Python):
import sys


def selection_sort(a, n):
    swap_count = 0
    for i in range(0, n):
        minj = min(range(i, n), key=a.__getitem__)
        if i != minj:
            a[i], a[minj] = a[minj], a[i]
            swap_count += 1
    return swap_count


n = int(sys.stdin.readline())
a = [int(v) for v in sys.stdin.readline().strip().split()]
count = selection_sort(a, n)

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

Solution (Python):




import sys
input = sys.stdin.readline


def selectionSort(l):
    cnt= min_i= 0
    for i in range(len(l)-1):
        min_i = i
        flg = False
        for j in range(i+1,len(l)):
            if l[min_i] > l[j]:
                min_i = j
                flg = True
        if flg == True:
            cnt += 1
            
            (l[i],l[min_i]) = (l[min_i],l[i]) 
    return l,cnt

def main():
    n = int(input())
    l = list(map(int,input().split()))
    (ans,cnt) = selectionSort(l)
    print (*ans)
    print (cnt)
if __name__ == '__main__':
    main()

Solution (Python):
def selectionSort(A, N):
	global cnt

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

	return A

if __name__ == '__main__':
	n = int(input())
	R = list(map(int, input().split()))
	cnt = 0
	R = selectionSort(R, n)
	print(" ".join(map(str, R)))
	print(cnt)

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


def selection_sort(Ary):
    N = len(Ary)
    count = 0
    for i in range(N-1):
        min_j = i
        flag = 0
        for j in range(N-i):
            if Ary[j+i] < Ary[min_j]:
                min_j = j+i
                flag = 1
        Ary[i], Ary[min_j] = Ary[min_j], Ary[i]
        if flag == 1:
            count += 1
            flag = 0
    return Ary, count

A_sorted , count = selection_sort(A)
print(' '.join(map(str, A_sorted)))
print(count)

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

k = 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:
        k += 1
        t = a[i]
        a[i] = a[minj]
        a[minj] = t
for i in range(0, n - 1):
    print(a[i], end=' ')
print(a[n - 1])
print(k)

Solution (Python):

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

flag = 1 
cnt = 0
point = 0
while point < N:
    rpoint = point
    for i in range(point,N,1):
        if A[rpoint] > A[i]:
            rpoint = i
    A[point], A[rpoint] = A[rpoint], A[point]
    if point != rpoint:
        cnt += 1
    point += 1

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

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 selectionsort(n,a):
    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 a, count

if __name__ == '__main__':
    n = int(input())
    a = [int(x) for x in input().split()]
    a, count = selectionsort(n,a)
    print(' '.join(map(str, a)))
    print(count)

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

Solution (Python):
n = int(input())

a = input().split()

a = [int(x) for x in a]

count = 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:
        tmp = a[i]
        a[i] = a[minj]
        a[minj] = tmp
        count += 1

for i,x in enumerate(a):
    if i != len(a)-1:
        print(x, end=" ")
    else:
        print(x, end="")
print()
print(count)

Solution (Python):
n=int(input())
lst=list(map(int,input().split()))
count=0
for i in range(n-1):
    minlst=min(lst[i:])
    if lst[i]==minlst:continue
    count+=1
    for j in range(i+1,n):
        if minlst==lst[j]:
            lst[i],lst[j]=lst[j],lst[i]
            break
print(*lst)
print(count)

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

def hyouji(a,change):
    for i in range(len(a)):
        if i==0:
            print(a[i],end="")
        else:
            print(" "+str(a[i]),end="")
    print()
    print(change)


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

hyouji(a,change)

Solution (Python):

"""
selection sort
"""
N = int(input())
aN = list(map(str, input().split()))

cnt = 0
for i in range(N):
    minj = i
    for j in range(i, N):
        if int(aN[j]) < int(aN[minj]):
            minj = j
    if i != minj:
        tmp = aN[i]
        aN[i] = aN[minj]
        aN[minj] = tmp
        cnt += 1
print(' '.join(aN))
print(cnt)

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

Solution (Python):
def selection_sort(num_list):
    cnt = 0

    for i in range(len(num_list)-1):
        min_idx = i
        for j in range(i,len(num_list)):
            if num_list[j] < num_list[min_idx]:
                min_idx = j
        if i != min_idx:
            num_list[i],num_list[min_idx] = num_list[min_idx],num_list[i]
            cnt += 1
    return cnt

n = int(input())
num_list = list(map(int,input().split()))
ans = selection_sort(num_list)
ans_list = [str(i) for i in num_list]

print(' '.join(ans_list))
print(ans)

Solution (Python):
def solve():
    size = int(input())
    array = list(map(int, input().split()))
    SelectionSort(array, size)


def SelectionSort(array, size):
    swap_count = 0
    for i in range(0, size, 1):
        minj = i
        for j in range(i, size, 1):
            if array[j] < array[minj]:
                minj = j
        if array[i] is not array[minj]:
            array[i], array[minj] = array[minj], array[i]
            swap_count += 1
    print(' '.join(map(str, array)))
    print(swap_count)


if __name__ == '__main__':
    solve()

Solution (Python):
def selection_sort(n, nums):
    cnt = 0
    for i in range(n):
        minj = i
        for j in range(i, n):
            if nums[j] <  nums[minj]:
                minj=j
        if i != minj:              
            tmp = nums[i]
            nums[i] = nums[minj]
            nums[minj] = tmp
            cnt += 1
            
    print(' '.join(map(str, nums)))
    print(cnt)

def main():
    n = int(input())
    line = input()
    nums = list(map(int, line.split()))

    selection_sort(n, nums)

if __name__ == "__main__":
    main()

Solution (Python):
def SelectionSort(A):
    swapCount=0
    
    for i in range(len(A)):
        mini=i
        for j in range(i,len(A)):
            if A[j]<A[mini]:
                mini=j
        if mini!=i:
            tmp=A[i]
            A[i]=A[mini]
            A[mini]=tmp
            swapCount+=1
    return swapCount
    


n=int(input())
nums=list(map(int, input().split()))
count=SelectionSort(nums)
maplist=map(str, nums)
print(' '.join(maplist))
print(count)

Solution (Python):
n = int(input())

blist = list(map(int, input().split()))

cnt = 0

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

for i in range(n):
    if i == n-1:
        print(blist[i])
    else:
        print(str(blist[i]) + " ", end="")

print(cnt)

Solution (Python):
import sys

def main():
    inputslen = int(sys.stdin.readline().rstrip())
    inputs= sys.stdin.readline()

    sortvalue = [int(i) for i in inputs.split()]
    count = 0
    for i in range(0, inputslen-1):

        minidx = i
        for j in range(i, inputslen):
            if sortvalue[j] < sortvalue[minidx]:
                minidx = j
        if sortvalue[minidx] != sortvalue[i]:
            minvalue = sortvalue[minidx]
            sortvalue[minidx] = sortvalue[i]
            sortvalue[i] = minvalue
            count += 1

    printvalue = map(str, sortvalue)
    print(' '.join(printvalue))
    print(count)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(0,N-1):
    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
print(*A)
print(count)

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
swap_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:
        a[i],a[minj] = a[minj],a[i]
        swap_count += 1
print(" ".join(map(str,a)))
print(swap_count)

Solution (Python):
class Selection_sort:
    def __init__(self):
        self.swap_num=0
    
    def sort(self,data):
        for i in range(len(data)):
            mini=i
            for j in range(i+1,len(data)):
                if(data[j] < data[mini]):
                    mini=j
            if(mini!=i):
                data[i],data[mini]=data[mini],data[i]
                self.swap_num+=1
        return data






n=int(input())
data=list(map(int,input().split()))
selection_sort=Selection_sort()
print(" ".join(list(map(str,selection_sort.sort(data)))))
print(selection_sort.swap_num)

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:
        A[i], A[minj] = A[minj], A[i]
        count += 1

for k in range(N):
        if k > 0:
            print(' ', end='')
        print(A[k], end='')

print('')
print(count)

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


n=int(input())
r=list(map(int,input().split()))
count_num = 0
for i in range(0, n):
    minj = i
    for j in range(i, n):
        if r[j] < r[minj]:
            minj = j
    v = r[minj]
    r[minj] = r[i]
    r[i] = v
    if minj != i:
        count_num += 1
print_list(r)
print(count_num)

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

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
        if A[i] != A[minj]:
            A[i], A[minj] = A[minj], A[i]
            cnt += 1
    return A, cnt

result = selectionSort(a, n)
print(' '.join(map(str, result[0])))
print(result[1])

Solution (Python):
def SelectionSort(A):
    n = 0
    for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if A[j]<A[mini]:
                mini=j
        if i!=mini:
            A[i], A[mini] = A[mini], A[i]
            n += 1
    print(' '.join(map(str, A)), n, sep='\n')

input()
SelectionSort(list(map(int, input().split())))

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

def selectionSort(list_a, n):
    count = 0
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if list_a[j] < list_a[minj]:
                minj = j
        (list_a[i], list_a[minj]) = (list_a[minj], list_a[i])
        if minj != i:
            count += 1
    return list_a,count

list_n, count = selectionSort(list_n, n)
print(" ".join(str(number) for number in list_n))
print(count)

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

print(" ".join(map(str, listA)))
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
        tmp = a[i]
        a[i] = a[minj]
        a[minj] = tmp

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

Solution (Python):
n = int(input())
a = 0
if n <= 0 or 101 <= n:
  exit()
list1 = list(map(int, input().split()))

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

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

Solution (Python):


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

for i in range(n):
    m=i
    for j in range(i,n):
        if a[m]>a[j]:m=j
    
    if i!=m:
        a[m],a[i]=a[i],a[m]
        flag+=1

print(*a)
print(flag)

Solution (Python):



N = int(input())
l = input().split(' ')
A = [int(i) for i in l]


def selectSort(A, N):
    counter = 0
    for i in range(N-1):
        minij = i
        for j in range(i + 1, N):
            if A[minij] > A[j]:
                minij = j

        if A[i] > A[minij]:
            v = A[i]
            A[i] = A[minij]
            A[minij] = v
            counter += 1

    map_list = map(str, A)
    a = ' '.join(map_list)
    print(a)
    print(counter)

selectSort(A, N)