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


def ss(array, length):
  cnt=0
  for i in range(length):
    minj = i
    v = array[i]
    for j in range(i, n):
      if array[minj]>array[j]:
        minj = j
    if array[i] != array[minj]:
      cnt+=1
    array[i] = array[minj]
    array[minj] = v
  return array, cnt

b, c = ss(a, n)

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

print()
print(c)

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

n = int(input())
a = list(map(int, input().split()))
ans, cnt = selection_sort(a, n)
print(*ans)
print(cnt)

Solution (Python):
def selection_sort(N, A):
    num = 0
    for i in range(N):
        minimum = A[i]
        flag = False
        for j in range(i+1, N):
            if A[j] < minimum:
                minimum = A[j]
                index = j
                flag = True
        if flag:
            A[i], A[index] = A[index], A[i]
            num += 1
    return [num, *A]

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    ans = selection_sort(N, A)
    print(*ans[1:])
    print(ans[0])

Solution (Python):
def selectionSort(a,n):
    r = 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 a[i] != a[minj]:
            r += 1
    return r


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

r = selectionSort(a,n)

print(*a)
print(r)

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

def selectionSort(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 i!=mini:
            tmp = A[i]
            A[i]=A[mini]
            A[mini] = tmp
            count += 1


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

selectionSort(A,N)

Solution (Python):
def selection_sort(array, n):
    count = 0
    for i in range(n):
        index_min = i
        for j in range(i, n):
            if array[j] < array[index_min]:
                index_min = j
        if array[index_min] < array[i]:
            array[i], array[index_min] = array[index_min], array[i]
            count += 1
    return count


def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    count = selection_sort(a, n)
    print(*a)
    print(count)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
arr = [x for x in list(map(int, input().split()))]

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

print (" ".join([str(x) for x in arr]))
print (count)

Solution (Python):
import re

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

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

print(re.sub("[\[\]\,]","",str(a)))
print(num)

Solution (Python):
def selection_sort(A):
    a = list(A)
    swap_count = 0

    for i in range(0, len(A)-1):
        i_min = i
        for j in range(i+1, len(A)):
            if a[j] < a[i_min]:
                i_min = j
        if i is not i_min:
            a[i], a[i_min] = a[i_min], a[i]
            swap_count += 1
    
    print(' '.join(map(str, a)))
    print(swap_count)

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

Solution (Python):
def s_sort(A,N):
   global count

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

   return A
  
if __name__=='__main__':
    n = int(input())
    R = list(map(int,input().split()))
    count = 0
    R = s_sort(R,n)
    print(" ".join(map(str,R)))
    print(count)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
c = 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:
        c += 1
print(" ".join(map(str, A)))
print(c)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
count = 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:
        x = a[i]
        a[i] = a[minj]
        a[minj] = x
        count = count + 1

print(*a)
print(count)

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

Solution (Python):
def print_list(a):
    out = ''
    for ai in a:
        out += str(ai) + ' '
    else:
        out = out[:-1]
    print(out)

def selection_sort(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 i != minj:
            tmp = a[i]
            a[i] = a[minj]
            a[minj] = tmp
            cnt += 1

    print_list(a)
    print(str(cnt))
    return a

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

a = selection_sort(a, n)

Solution (Python):
def SelectionSort(A, N):
    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:
            cnt +=1
        A[i], A[minj] = A[minj], A[i]       
    return A, cnt

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

ans, cnt = SelectionSort(A, N)

print(*A)
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,n):
    if A[j] < A[minj]:
      minj = j
  if i != minj:
    A[i], A[minj]=A[minj],A[i]
    count += 1
a=map(str,A)
print(" ".join(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())
working_list = list(map(int, input().split()))
exchange_count = 0
for i in range(N):
    minj = i
    for j in range(i+1, N):
        if working_list[j] < working_list[minj]:
            minj = j
    if i != minj:
        working_list[i], working_list[minj] = working_list[minj], working_list[i]
        exchange_count += 1

print(*working_list)
print(exchange_count)

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

    print(*A)
    print(cnt)

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

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

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

main()

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

b = [str(i) for i in a]
print(" ".join(b))
print(count)

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

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

Solution (Python):



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

count = 0
for i in range(length):
    minpos = i
    for j in range(i+1, length):
        if list[minpos] > list[j]:
            minpos = j

    if i != minpos:
        count += 1
    list[i], list[minpos] = list[minpos], list[i]

result = ''
for l in list:
    result += str(l) + ' '

print(result[:-1])
print(count)

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

print(*A)
print(count)

Solution (Python):
def selection_sort(A, N):
    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:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            swap_count += 1
    return A, swap_count
N = int(input())
A = list(map(int, input().split(' ')))
sorted_A, swap_count = selection_sort(A, N)
print(" ".join(map(str, sorted_A)))
print(swap_count)

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

def selectsort(A,n):
    count=0
    for i in range(len(A)):
        minj=i
        flag=0
        for j in range(i,len(A)):
            if A[j]<A[minj]:
                minj=j
                flag=1
        if flag==1:
            tmp=A[minj]
            A[minj]=A[i]
            A[i]=tmp
            count+=1
    return(A,count)

result,count=selectsort(A,n)
print(" ".join([str(i) for i in result]))
print(count)

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

Solution (Python):
def show (a,n):
  for i in range(n):
    if i > 0:
      print("",end=" ")
    print(a[i],end="")
  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[minj],a[i] = a[i],a[minj]
    if minj != i:
      count += 1
  show(a,n)
  print(count)

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

selectionSort(a,n)

Solution (Python):
def SelectionSort(N, A):
    count = 0
    if N == 1:
        print(str(A[0]) + "\n" + str(0))
    else:
        for i in range(N - 1):
            A_r = A[i:] 
            mini = min(A_r)
            mini_index = i + A_r.index(mini) 
            if A[i] > mini:
                count += 1
                A[i], A[mini_index] = A[mini_index], A[i] 

        str_A = map(str, A)
        print(" ".join(str_A) + "\n" + str(count))


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

Solution (Python):

def ALDS1_2_B():
    """
    1 selectionSort(A, N) // N個の要素を含む0-オリジンの配列A
    2   for i が 0 から N-1 まで
    3     minj = i
    4     for j が i から N-1 まで
    5       if A[j] < A[minj]
    6         minj = j
    7     A[i] と A[minj] を交換

    ＜問題＞
    数列Aを読み込み、選択ソートのアルゴリズムで昇順に並び替え出力するプログラムを作成してください。
    上の疑似コードに従いアルゴリズムを実装してください。
    疑似コード 7 行目で、i と minj が異なり実際に交換が行われた回数も出力してください。

    ＜入力＞
    入力の最初の行に、数列の長さを表す整数 N が与えられます。２行目に、N 個の整数が空白区切りで与えられます。

    ＜出力＞
    出力は 2 行からなります。１行目に整列された数列を 1 行に出力してください。
    数列の連続する要素は１つの空白で区切って出力してください。2 行目に交換回数を出力してください。

    ＜制約＞
    1 ≤ N ≤ 100
    0 ≤ A の要素 ≤ 100
    """
    N = int(input())
    A = [int(e) for e in input().split(" ")]
    switch_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]
            switch_cnt += 1
    print(" ".join(map(str, A)))
    print(switch_cnt)


def main():
    ALDS1_2_B()


if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    N = sc.intarr()[0]
    A = sc.intarr()

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


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


main()

Solution (Python):
def selection_sort(a, n):

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

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


def main():
    n = int(input())
    a = list(map(int, input().split(' ')))
    selection_sort(a, n)


if __name__ == "__main__":
    main()

Solution (Python):
N, *A = map(int, open(0).read().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(map(str, A)))
print(ans)

Solution (Python):



def selectionSort(A, N):
    cnt = 0
    for i in range(0, N-1):
        minj = i
        mink = i
        for j in range(i, N):
            if A[mink] > A[j]:
                mink = j
        if minj != mink:
            A[minj], A[mink] = A[mink], A[minj]
            cnt += 1

                
    showResult(A, cnt)

def showResult(A, cnt):
    for i in range(N-1):
        print(A[i], end=" ")
    print(A[N - 1])
    print(cnt)
        


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

Solution (Python):
cou = 0

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

for i in range(N):
  minj = i
  for j in range(i,N):
    if l[j] < l[minj]:
      minj = j
  if not l[i] == l[minj]:
    a = l[i]
    b = l[minj]
    l[i] = b
    l[minj] = a
    cou += 1

print(" ".join(map(str,l)))
print(cou)

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

for i in range(n):
    min_j = i
    for j in range(i+1,n):
        if A[j] < A[min_j]:
            min_j = j
    if min_j != i:
        buf = A[i]
        A[i] = A[min_j]
        A[min_j] = buf
        cnt += 1
for k in range(n):
    if k != n-1:
        print(A[k],"",end="")
    else:
        print(A[k])
print(cnt)

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

count = 0
for i in range(N-1):
    minj = i
    increment = 0
    for j in range(i+1, N):
        if A[minj] > A[j]:
            minj = j
            increment = 1
    count += increment
    A[i], A[minj] = A[minj], A[i]
print(*A)
print(count)

Solution (Python):

def selection_sort(a):
    size = len(a)
    cnt = 0
    for i in range(size):
        mini = i
        for j in range(i,size):
            if a[j] < a[mini]:
                mini = j
        if mini != i:
            a[i], a[mini] = a[mini], a[i]
            cnt += 1
    return (a, cnt)


_ = input()
l = [ int(s) for s in input().split() ]
(nl,swap) =  selection_sort(l)

print(*nl)
print(swap)

Solution (Python):
n=int(input())
A=[int(i) for i in input().split()]

count=0

for i in range(0,n,1):
  minj=i
  for j in range(i+1,n,1):
    if A[minj] > A[j]:
      minj=j
  if i != minj:
    a= A[i]
    A[i]=A[minj]
    A[minj]=a
    count+=1
  
print(*A, sep=' ')
print(count)

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

for i in range(n):
    mini = array[i]
    mini_idx = i
    for j in range(i, n):
        if mini > array[j]:
            mini = array[j]
            mini_idx = j
    if i != mini_idx:
        array[i], array[mini_idx] = array[mini_idx], array[i]
        swaped += 1
print(' '.join([str(e) for e in array]))
print(swaped)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    ans=0
    for i in range(n):
        min_j=i
        for j in range(i+1,n):
            if aa[j]<aa[min_j]:min_j=j
        if min_j!=i:
            aa[i],aa[min_j]=aa[min_j],aa[i]
            ans+=1
    print(*aa)
    print(ans)

main()

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

print(*A)
print(cnt)

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

def selectionSort(A, N):
    cnt = 0
    
    for i in range(N):
        A_ = A[i:]
        j = A_.index(min(A_)) + i
        if A[j] < A[i]:
            temp = A[i]
            A[i] = A[j]
            A[j] = temp
            cnt += 1
                
    print(*A)
    print(cnt)
    
selectionSort(A, N)

Solution (Python):
def selection(l):
    count = 0
    for i in range(len(l)):
        minj = i
        for j in range(i,len(l)):
            if l[j] < l[minj]:
                minj = j
        if l[i] > l[minj]:
            a = l[i]
            l[i] = l[minj]
            l[minj] = a
            count += 1
    ans_l = map(str,l)
    return ans_l,count
n = int(input())
l = list(map(int,input().split()))
ans_l,count = selection(l)
print(' '.join(ans_l))
print(count)

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

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

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

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


def main():
    n = int(input())
    arr = list(map(int, input().split()))
    
    
    arr, count = selection_sort(arr, n)
    print(" ".join(map(str, arr)))
    print(count)


if __name__ == "__main__":
    main()

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

cnt = 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]
        cnt += 1
print(*A)
print(cnt)

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

def selection_sort(A):
    cnt = 0
    for i in range(len(A)-1):
        minj = i
        for j in range(i+1,len(A)):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            cnt += 1
        A[minj],A[i] = A[i],A[minj]
    print(*A)
    print(cnt)

selection_sort(A)

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

Solution (Python):
def selectionSort(numlist):
    n = len(numlist)
    swaptime = 0
    for i in range(n):
        min_index = i
        for j in range(i + 1, n):
            if numlist[j] < numlist[min_index]:
                min_index = j
        if min_index != i:
            numlist[i], numlist[min_index] = numlist[min_index], numlist[i]
            swaptime += 1
    return swaptime

def print_numlist(numlist):
    if len(numlist) == 1:
        print(numlist[0])
    else:
        for i in range(0, len(numlist) - 1):
            print(numlist[i], end = ' ')
        print(numlist[-1])

if __name__ == '__main__':
    n = int(input())
    numlist = [int(i) for i in input().replace('\n', '').split(' ')]
    swapnum =  selectionSort(numlist)

    print_numlist(numlist)
    print(swapnum)

Solution (Python):
n=int(input())
l=list(map(int, input().split()))
cnt=0
for i in range(n):
    if n==1:
        break
    elif l[i]!=min(l[i:n]):
        num=l[i:n].index(min(l[i:n]))+i
        l[i],l[num]=l[num],l[i]
        cnt+=1
print(*l)
print(cnt)

Solution (Python):








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


print(*nums)
print(count)

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+1, N):
        if A[j] < A[minj]:
            minj = j
    if minj != i:
        A[i], A[minj] = A[minj], A[i]
        counter += 1
    
print(' '.join([str(i) for i in A]))
print(counter)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
change = 0
for i in range(n-1):
	minA = 1000
	doko = 0
	for u in range(i+1, n):
		if minA > a[u]:
			minA = a[u]
			doko = u
	if minA < a[i]:
		a[i], a[doko] = a[doko], a[i]
		change += 1
print(*a)
print(change)

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
  A[i], A[minj] = A[minj], A[i]
  if i != minj:
    counter += 1
print(*A, sep=" ")
print(counter)

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

for i in range(N):
    minj = i
    for j in range(i, N):
        if A[j] < A[minj]:
            minj = j
    if i != minj:
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
        sum += 1
print(*A)
print(sum)

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


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

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



num_swap = 0
for i in range(n):
    index = -1
    mini = num_list[i]
    for j in range(i, n):
        if mini > num_list[j]:
            index = j            
            mini = num_list[j]
    if index > -1:
        num_swap += 1
        num_list[i], num_list[index] = num_list[index], num_list[i]
print(' '.join(map(str, num_list)))
print(num_swap)

Solution (Python):
def selection_sort(a, n):
    number = 0
    for i in range(n):
        min_index = a[i:].index(min(a[i:])) + i
        a[min_index], a[i] = a[i], a[min_index]
        if i != min_index:
            number += 1
    return number


n = int(input())
*ls, = map(int, input().split())
num = selection_sort(ls, n)
print(*ls)
print(num)

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

c = 0
for i in range(N):
  mat = i
  for j in range(i, N):
    if A[j] < A[mat]:
      mat = j
  if i != mat:
    t = A[i]
    A[i] = A[mat]
    A[mat] = t
    c += 1

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

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
    if minj != i:
      count += 1
    a[i],a[minj] = a[minj],a[i]
  return count
  
count = selectionSort(a,n)
print(*a)
print(count)

Solution (Python):
n = int(input())
a = [int(i) for i in input().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(' '.join(map(str,a)))
print(c)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
cnt=0
judge=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]:
        a[i],a[minj]=a[minj],a[i]
        cnt+=1
   
for i in range(n):
    if i==0:
        print(a[i],end="")
    else:
        print("{: }".format(a[i]),end="")
print()
print(cnt)

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

def selection_sort(a):
    global cnt
    for i in range(len(a)):
        min_idx = i
        for j in range(i + 1, len(a)):
            if a[j] < a[min_idx]:
                min_idx = j
                
        if i != min_idx:
            a[i], a[min_idx] = a[min_idx], a[i]
            cnt += 1

selection_sort(a)
print(*a)
print(cnt)

Solution (Python):
import sys
input = sys.stdin.readline

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

def SelectionSort(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
    print(*A)
    print(count)
SelectionSort(N)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
ans=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]
        ans+=1
print(*a)
print(ans)

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

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

Solution (Python):

def print_output(_list):
    for index in range(len(_list)):
        if index == len(_list) - 1:
            print(_list[index])
        else:
            print(_list[index],end=' ')

target_length = int(input())
target_list = list(map(int,input().split()))
choice_count = 0
for i in range(0, target_length - 1):
    minj = i
    for j in range(i, len(target_list)):
        if target_list[j] < target_list[minj]:
            minj = j
    if i != minj:
        choice_count += 1
    tmp = target_list[i]
    target_list[i] = target_list[minj]
    target_list[minj] = tmp
print_output(target_list)
print(choice_count)

Solution (Python):
cnt = 0
def SelectionSort(L):
    global cnt
    for i in range(len(L)):
        minj = i
        for j in range(i+1, len(L)):
            if L[minj] > L[j]:
                minj = j
        if minj != i:
            cnt += 1
            L[i], L[minj] = L[minj], L[i]

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

SelectionSort(NUM_LIST)
STR = list(map(str, NUM_LIST))
print(" ".join(STR))
print(cnt)

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


if __name__ == "__main__":
	n = int(input())
	a = list(map(int, input().split()))
	selectionSort(a, n)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in range (0, N-1):
    min = i
    for j in range(i+1, N):
        if A[j] < A[min]:
            min = j
    if min == i:
        continue
    else:
        tmp = A[min]
        A[min] = A[i]
        A[i] = tmp
        cnt += 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[minj]>A[j]:
                minj=j
        if A[i]!=A[minj]:
            A[i],A[minj]=A[minj],A[i]
            cnt+=1
    return A,cnt

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

    for b in range(N):
      print(A[b], end=" \n"[b + 1 == N])
    print(cnt)


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

SelectionSort(A, N)

Solution (Python):
def SelectionSort(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
        if A[i] != A[mini]:
            A[i], A[mini] = A[mini], A[i]
            count += 1
    return A, count

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