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())
s = [int(x) for x in input().split()]

swap_cnt = 0

for i in range(n) :
    cmin = i
    for j in range(i + 1, n) :
        if s[j] < s[cmin] :
            cmin = j
            
    if i != cmin :
        s[i], s[cmin] = s[cmin], s[i]
        swap_cnt += 1
                
print(" ".join(map(str, s)))
print(swap_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:
            k = A[i]
            A[i] = A[minj]
            A[minj] = k
            count += 1
    print(" ".join(map(str, A)))
    print(count)


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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
c=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:c+=1
print(*a)
print(c)

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

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

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

Solution (Python):
def print_list(A):
    print(*A, sep=" ")

def swap(a, b):
    return b, a

def find_minj(A, i, n):
    minj = i
    for j in range(i, n):
        if A[j] < A[minj]:
            minj = j
    return minj

def selection_sort(A, n):
    replace_num = 0
    for i in range(0, n):
        minj = find_minj(A, i, n)
        if A[i] > A[minj]:
            A[i], A[minj] = swap(A[i], A[minj])
            replace_num += 1
    print_list(A)
    print(replace_num)

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

selection_sort(A, n)

Solution (Python):


length = int(input())
array = [int(i) for i in input().rstrip().split()]

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

for i in range(length):
    if i < length - 1:
        print(array[i], end = " ")
    else:
        print(array[i])
print(count)

Solution (Python):
def selection_sort(a, n):
    sw_num = 0
    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
            sw_num += 1

    return sw_num


n = int(input())
a = [int(i) for i in input().split()]

sw_num = selection_sort(a, n)

print(' '.join([str(i) for i in a]))
print(sw_num)

Solution (Python):
def selectionSort(a, n):
  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:
      w = a[i]
      a[i] = a[minj]
      a[minj] = w
      count += 1
  print(' '.join(map(str, a)))
  print(count)

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

Solution (Python):





def formatting(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 - 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

    formatting(A)
    print(count)



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

selectionSort(inputList, N)

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

Solution (Python):
def insection_sort(lst):
    lens=len(lst)
    ans=0
    for i in xrange(lens):
        mn=i
        for j in xrange(i+1,lens):
            if(lst[j]<lst[mn]):
                mn=j
        if(mn!=i):
            tmp=lst[i]
            lst[i]=lst[mn]
            lst[mn]=tmp
            ans+=1
    return ans
num=int(raw_input().strip())
arr=map(int,raw_input().strip().split())
ans=insection_sort(arr)
print " ".join(str(pp) for pp in arr)
print ans

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 i != minj:
            cnt += 1
    return cnt

N = int(input())
A = list(map(int, input().split()))
cnt = selection_sort(A, N)
print(*A)
print(cnt)

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

Solution (Python):
def selection_sort(num_list):
    list_length = len(num_list)
    cnt = 0
    
    for i in range(list_length):
        min_element = i
        for j in range(i+1,list_length):
            if num_list[j] < num_list[min_element]:
                min_element = j
        if i != min_element:
            num_list[i],num_list[min_element] = num_list[min_element],num_list[i]
            cnt += 1
    return num_list,cnt

n = int(input())
num_list = list(map(int,input().split()))
ans_list,cnt = selection_sort(num_list)
str_ans_list = [str(i) for i in ans_list]
print('{}\n{}'.format(' '.join(str_ans_list),cnt))

Solution (Python):
n = int(input())
a = [int(i) for i in 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 minj != i:
        a[i], a[minj] = a[minj], a[i]
        counter += 1
print(*a)
print(counter)

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

    cnt = 0
    for i in range(n):
        min_idx = i
        for j in range(i+1, n):
            if array[min_idx] > array[j]:
                min_idx = j
        if min_idx != i:
            tmp = array[i]
            array[i] = array[min_idx]
            array[min_idx] = tmp
            cnt += 1

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


main()

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):
def showList(A, N):
    for i in range(N-1):
        print(A[i],end=' ')
    print(A[N-1])

def selectionSort(A, N):
    """
    選択ソート
    O(n^2)のアルゴリズム
    """
    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:
            t = A[minj]
            A[minj] = A[i]
            A[i] = t
            count += 1
    showList(A, N)
    print(count)
    

N = int(input())
A = [int(x) for x in 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
        else:
            pass
    A[i], A[minj] = A[minj], A[i]
    if i != minj:
        count += 1
        
print(*A)
print(count)

Solution (Python):
def selectionSort(A):
    n = len(A)
    cnt = 0
    for i in range(n):
        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]
            cnt += 1
    print(*A)
    print(cnt)

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

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 = A[i]
        A[i] = A[minj]
        A[minj] = a

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

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

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

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

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

swap_count = 0
for i in range(n):
    flag = False
    minj = i
    for j in range(i, n):
        if a[j] < a[minj]:
            minj = j
            flag = True
    if flag:
        a[i], a[minj] = a[minj], a[i]
        swap_count += 1

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

Solution (Python):
from typing import List


def selection_sort(A: List[int]) -> int:
    cnt = 0
    for i in range(len(A)):
        min_j = i
        for j in range(i, len(A)):
            if A[j] < A[min_j]:
                min_j = j
        if min_j != i:
            cnt += 1
        A[i], A[min_j] = A[min_j], A[i]
    return cnt


N = int(input())
A = [int(i) for i in input().split()]
cnt = selection_sort(A)
print(' '.join(map(str, A)))
print(cnt)

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


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

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

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

count = 0
for i in range(n):
    mini = i + a[i:].index(min(a[i:]))
    if mini != i:
        a[i], a[mini] = a[mini], a[i]
        count += 1

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

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

count=0
for i in range(n):
    m=i
    for j in range(i,n):
        if l[j]<l[m]:
            m=j
    l[i],l[m]=l[m],l[i]
    if l[i]!=l[m]:
        count+=1
print(*l)
print(count)

Solution (Python):
def selectionsort(l,n):
    c=0
    for i in range(n):
        minj=i
        for j in range(i,n):
            if int(l[j])<int(l[minj]):
               minj=j
        l[i],l[minj]=l[minj],l[i]
        if i!=minj:
          c+=1
    print(" ".join(l))
    print(c)
n=int(input())
l=list(input().split())
selectionsort(l,n)

Solution (Python):




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

    return A, sw

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))

    A_sorted, sw = selectionSort(A, N)

    for i in range(0, N - 1):
        print(A[i], end=" ")
    print(A[N - 1])
    print(sw)

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+1,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()))
count = 0
for i in range(0, n):
	minj = min(range(i, n), key=lambda j: a[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()))
count = 0
for i in range(n):
	minj = min(range(i, n), key=lambda j: a[j])
	if i != minj:
		a[i], a[minj] = a[minj], a[i]
		count += 1
print(*a)
print(count)

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

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

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

print(*a)
print(count)

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

chg = 0
for i in range(num-1):

	minv = i+1
	for j in range(i+2,num):
		if A[minv] > A[j]:
			minv = j

	if A[i] > A[minv]:
		A[i],A[minv] = A[minv],A[i]
		chg += 1
print(*A)
print(chg)

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

chg = 0
for i in range(num-1):

	minv = i
	for j in range(i+1,num):
		if A[minv] > A[j]:
			minv = j

	if A[i] > A[minv]:
		A[i],A[minv] = A[minv],A[i]
		chg += 1
print(*A)
print(chg)

Solution (Python):
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[j]<a[minj]:
            j,minj=minj,j
    if i!=minj:
        a[i],a[minj]=a[minj],a[i]
        ans+=1
print(' '.join(map(str,a)))
print(ans)

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

for i in range(n):
    minj = i

    for j in range(i + 1, n):

        if nums[j] < nums[minj]:
            minj = j

    else:
        if nums[i] > nums[minj]:
            temp = nums[minj]
            nums[minj] = nums[i]
            nums[i] = temp
            count += 1

print(' '.join([str(i) for i in nums]))
print(count)

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

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

    print(*a)
    print(ans)


if __name__ == '__main__':
    main()

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

n = int(input())
A = list(map(int, input().split()))
count = selection_sort(A)
print(*A)
print(count)

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
    return A,count

N = int(input())
A = list(map(int,input().split()))
A,count = selectionSort(A,N)
print(" ".join(map(str,A)))
print("%d"%(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, 1):
        if A[j] < A[minj]:
            minj = j
    if i != minj:
        A[i], A[minj] = A[minj], A[i]
        count += 1

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

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
c = 0
min = 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]
        c += 1
    
print(*a)
print(c)

Solution (Python):
def selection_sort(A):
    n = len(A)
    num_swaps = 0
    for i in range(n):
        min_idx = i
        for j in range(i, n):
            if A[j] < A[min_idx]:
                min_idx = j
        if min_idx != i:
            A[i], A[min_idx] = A[min_idx], A[i]
            num_swaps += 1
    return num_swaps


N = int(input())
A = [int(elem) for elem in input().split()]
num_swaps = selection_sort(A)
print(*A)
print(num_swaps)

Solution (Python):

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

count = 0 
for i in range(N):
    minj = i
    for j in range(i+1,N): 
        if nums[minj] > nums[j]:
            minj = j
    if i != minj:
        temp = nums[i] 
        nums[i] = nums[minj] 
        nums[minj] = temp
        count = count + 1

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
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
        A[i], A[minj] = A[minj], A[i]
    
print(" ".join(map(str, A)))
print(sw)

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

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

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

Solution (Python):
N = input()
n = map(int,raw_input().split(' '))
c = 0
for i in range(N-1):
	mini = i
	for j in range(i+1,N):
		if n[mini] > n[j]:
			mini = j
	if mini != i:
		temp = n[i]
		n[i] = n[mini]
		n[mini] = temp
		c+=1
print " ".join(str(i) for i in n)
print c

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

Solution (Python):
n = raw_input()
A = map(int, raw_input().split())
cnt = 0
for i in xrange(len(A)):
    mini = i
    for j in xrange(i, len(A)):
        if A[j] < A[mini]:
            mini = j
    if A[i]!=A[mini]:
	    cnt += 1
	    A[i], A[mini] = A[mini], A[i]
for x in A:
	print x,
print
print cnt

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

print(*A)
print(count)

Solution (Python):
def selectionSort(A, N): 
    m = 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:
            m += 1
    print ' '.join(map(str,A))
    print m

N = int(raw_input())
A = map(int,raw_input().split())
selectionSort(A,N)

Solution (Python):
def selection_sort(A):
    count = 0
    for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if A[j] < A[mini]:
                mini = j
        count += swap(A, mini, i)
    print_array(A)
    return count


def swap(A, i, j):
    if i != j:
        tmp = A[j]
        A[j] = A[i]
        A[i] = tmp
        return 1
    else:
        return 0


def print_array(array):
    print(" ".join([str(x) for x in array]))


amount = int(input())
numbers = [0 for i in range(amount)]
numbers = list(map(int, input().split()))
count = selection_sort(numbers)
print(count)

Solution (Python):



import sys

nums_len = int(sys.stdin.readline())
nums_str = sys.stdin.readline().split(' ')
nums = map(int, nums_str)

swap_count = 0
for i in range(0, nums_len):
    minj = i
    for j in range(i, nums_len):
        if nums[j] < nums[minj]:
            minj = j
    if minj != i:
        v = nums[i]
        nums[i] = nums[minj]
        nums[minj] = v
        swap_count += 1

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

Solution (Python):
def selectionSort( nums ):
	cnt = 0
	for i in range( 0, len( nums ) ):
		mini = i
		for j in range( i , len( nums ) ):
			if nums[j] < nums[ mini ]:
				mini = j
		if mini != i:
			cnt += 1
			nums[i], nums[ mini ] = nums[ mini ], nums[i]

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


n = int( raw_input( ) )
nums = [ int( val ) for val in raw_input( ).split( " " ) ]
selectionSort( nums )

Solution (Python):
def selectionSort( nums ):
	cnt = 0
	for i in range( 0, len( nums ) ):
		mini = i
		for j in range( i , len( nums ) ):
			if nums[j] < nums[ mini ]:
				mini = j
		if mini != i:
			cnt += 1
			nums[i], nums[ mini ] = nums[ mini ], nums[i]

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


n = int( input( ) )
nums = [ int( val ) for val in input( ).split( " " ) ]
selectionSort( nums )

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
c = 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:
        c += 1

print(' '.join((str(x) for x in A)))
print(c)

Solution (Python):

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

def selectionSort(ary):
    count = 0
    for i in range(len(ary)):
        minj = i
        for j in range(i, len(ary)):
            if ary[minj] > ary[j]:
                minj = j
        if minj != i:
            ary[minj], ary[i] = ary[i], ary[minj]
            count += 1
    return (ary, count)

result = selectionSort(numbers)
print(*result[0])
print(result[1])

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

if __name__ == '__main__':
    n = int(input())
    array, count = selection_sort(list(map(int, input().split())))
    print(' '.join(map(str, array)))
    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
    if i != mini:
        a[i], a[mini] = a[mini], a[i]
        count += 1

print(*a)
print(count)

Solution (Python):


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

def main():
	N = input()
	A = map(int, raw_input().split())
	sorted_, count = selectionSort(A, N)
	print ' '.join(map(str, sorted_))
	print count

if __name__ == '__main__':
	main()

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

Solution (Python):


def selection_sort(ary, n):
    count = 0
    for i in range(n):
        minj = i
        for j in range(i, n):
            if ary[minj] > ary[j]:
                minj = j
        if ary[minj] != ary[i]:
            ary[minj], ary[i] = ary[i], ary[minj]
            count += 1
    print(*ary)
    print(count)

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

Solution (Python):
def selection_sort(a,n):
    m=0
    for i in range(0,n):
        minj=i
        for j in range(i,n):
            if(a[minj] > a[j]):
                minj=j
        if(minj!=i):
            m+=1
            
            a[minj],a[i] = a[i],a[minj]
        
    b=list(map(str,a))
    print(" ".join(b))
    print(m)

a=[]
n=int(input())
s=input()
a=list(map(int,s.split()))
selection_sort(a,n)

Solution (Python):
n = int(input())
s = input()
A = list(map(int,s.split()))
flag = 1
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]):
        tmp = A[i]
        A[i] = A[minj]
        A[minj] = tmp
        cnt += 1


for k in range(0,len(A)-1):
    print(A[k],end=" ")
print(A[len(A)-1])
print (cnt)

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

s = raw_input()

count = 0

num_list= s.split(" ")
for i in range(n):
    num_list[i] = int(num_list[i])

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

print " ".join([str(a) for a in num_list])
print count

Solution (Python):
N = int(raw_input())
A = map(int, raw_input().split())
count = 0
for i in range(0, N):
    min_j = i
    c = 0
    for j in range(i, N):
        if A[j] < A[min_j]:
            min_j = j
            c = 1
    A[i], A[min_j] = A[min_j], A[i]
    count += c
print " ".join(map(str, A))
print count

Solution (Python):

numbers = []
n = int(raw_input())
s = raw_input()
count = 0

numbers = s.split(" ")
for i in range(int(n)):
	numbers[i] = int(numbers[i])

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

print ' '.join([str(a) for a in numbers])
print count

Solution (Python):
N = int(raw_input())
num_list = map(int, raw_input().split())
c = 0

for i in range(0,N,1):
    flag =0
    minj =i
    for j in range(i,N,1):
        if num_list[j] < num_list[minj]:
            minj = j
            flag = 1
    c += flag
    num_list[i], num_list[minj] = num_list[minj], num_list[i]
print " ".join(map(str,num_list))
print c

Solution (Python):
import sys

lines = sys.stdin.readlines()

N = lines[0]
A = lines[1].strip().split(" ")

count = 0
for i in range(len(A)):
    minj = i
    for j in range(i, len(A)):
        if int(A[j]) < int(A[minj]):
            minj = j
    if i != minj:
        a = A[i]
        b = A[minj]
        A[i] = b
        A[minj] = a
        count += 1

print " ".join(A)
print count

Solution (Python):
N = int(raw_input())
A = raw_input().split(" ")

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

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

print " ".join(A)
print count

Solution (Python):
import sys

def selectionSort(x_list, y):
  a = 0
  for i in range(y):
    minj = i
    for j in range(i, y):
      if x_list[j] < x_list[minj]:
        minj = j
    x_list[i], x_list[minj] = x_list[minj], x_list[i]
    if x_list[i] != x_list[minj]:
      a += 1
  return a

y = sys.stdin.readline()
y = int(y)
 
x = sys.stdin.readline()
x_list = x.split(" ")
 
for i in range(y):
  x_list[i] = int(x_list[i])
 
a = selectionSort(x_list, y)
 
for k in range(0, y):
  print x_list[k],
print
print a

Solution (Python):
input()
num_list = raw_input().split()
num_list = map(int, num_list)

def selection_sort(num_list, count): 
    for i in range(0, len(num_list)):
        minj = i 
        for j in range(i, len(num_list)):
            if num_list[j] < num_list[minj]:
                minj = j 
                temp = num_list[minj]
        if minj != i:
            num_list[minj] = num_list[i]
            num_list[i]= temp
            count += 1
        i += 1
    return count, num_list

count = 0 
count, num_list = selection_sort(num_list, count)
num_list = map(str, num_list)
print " ".join(num_list)
print count

Solution (Python):
input()
num_list = raw_input().split()
num_list = map(int, num_list)

def selection_sort(num_list, count): 
    for i in range(0, len(num_list)):
        minj = i 
        for j in range(i, len(num_list)):
            if num_list[j] < num_list[minj]:
                minj = j 
        if minj != i:
            temp = num_list[minj]
            num_list[minj] = num_list[i]
            num_list[i]= temp
            count += 1
        i += 1
    return count, num_list

count = 0 
count, num_list = selection_sort(num_list, count)
num_list = map(str, num_list)
print " ".join(num_list)
print count

Solution (Python):
def input_number():
    num = raw_input()
    array = num.strip().split(" ")
    int_array = map(int, array)

    return int_array


def main():
    n = raw_input()
    count = 0
    int_array = input_number()
    for i in range(int(n)):
        minj = i
        for j in range(i, int(n)):
            if int_array[j] < int_array[minj]:
                minj = j
        v = int_array[i]
        int_array[i] = int_array[minj]
        int_array[minj] = v
        if minj != i:
            count += 1
    array = map(str, int_array)
    print " ".join(array)
    print count


if __name__ == '__main__':
    main()

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

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

cnt = 0

for i in range(n - 1):
    min_i = i
    for j in range(i + 1, n):
        if A[min_i] > A[j]:
            min_i = j
    if min_i != i:
        A[min_i], A[i] = A[i], A[min_i]
        cnt += 1

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

Solution (Python):
def selection_sort(List):
	cnt = 0
	l=len(List)
	for i in range(l):
		num_index=i
		for j in range(i,l):
			if List[num_index]>List[j]:
				num_index=j
		if num_index != i:
			temp=List[num_index]
			List[num_index]=List[i]
			List[i]=temp
			cnt+=1
	return cnt
N=input()
N_List=map(int,raw_input().split())
cnt=selection_sort(N_List)
print(" ".join(map(str,N_List)))
print(cnt)

Solution (Python):




def print_array(a):
    print(" ".join(map(str, a)))


def selectionsort(arr, n):
    a = arr[:]
    s = 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])
            s += 1
    return (a, s)


def main():
    n = int(input())
    arr = list(map(int, input().split()))
    (a, s) = selectionsort(arr, n)
    print_array(a)
    print(s)


if __name__ == "__main__":
    main()