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] 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



Sample input:
6
5 6 4 2 1 3


Sample output:
1 2 3 4 5 6
4

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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())))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#65
#ALDS1_2_B
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)

Submission status: Accepted

Solution code:
#! python3
# selectSort.py - 選択ソートを行う 配列の端から、残りのすべての数の一番小さい数と交換していく

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

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)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(_) for _ in input().split()]
count = 0
for i in range(n-1):
    tmp_index = i
    for j in range(i+1, n):
        # 最小の値探索
        # print("# temp", tmp_index, "j", j)
        if a[j] < a[tmp_index]:
            tmp_index = j
    if tmp_index != i:
        count += 1
        # 最小と左端入れ替え
        a_tmp = a[i]
        a[i] = a[tmp_index]
        a[tmp_index] = a_tmp
for i in range(n-1):
    print(a[i], end=" ")
print(a[n-1])
print(count)

Submission status: Accepted

Solution code:
def main():
    input()
    times = 0
    sequence = list(map(int, input().split()))
    for i in range(len(sequence)):
        mini = i
        for j in range(i, len(sequence)):
            if sequence[j] < sequence[mini]:
                mini = j
        if i != mini:
            times += 1
        sequence[i], sequence[mini] = sequence[mini], sequence[i]
    print(' '.join(map(str, sequence)))
    print(times)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

cnt = 0
for i in range(0, N):
    mini = i
    # search for the minimum element in A[i, i+1, ..., N-1]
    for j in range(i,N):
        if A[j] < A[mini]:
            mini = j
    # swap A[i] and A[mini]
    if i != mini:
        cnt += 1
        A[i], A[mini] = A[mini], A[i]
    
print( ' '.join(map(str, A) ) )
print(cnt)

Submission status: Accepted

Solution code:
cnt = int(input())
numbers = list(map(int, input().split(' ')))


def selectionsort(A, N):
    '''
    :param A: N個の要素を含む０オリジンの配列
    :param N: Aの要素数
    :return:
    '''
    swap_cnt = 0

    for i in range(0, 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]
            swap_cnt += 1

    return ' '.join(map(str, A)), swap_cnt

numbers, swap_cnt = selectionsort(numbers, cnt)
print(numbers)
print(swap_cnt)

Submission status: Accepted

Solution code:

def selection_sort(array):
    A = array[:]
    count = 0
    for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if int(A[j]) < int(A[mini]):
                mini = j
        if i != mini:
            A[i], A[mini] = A[mini], A[i]
            count += 1

    return A, count

_, array = input(), input().split()

result, count = selection_sort(array)

print(' '.join(result))
print(count)

Submission status: Accepted

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

s_count = 0
i = 0

while i < N:

    min_j = i
    j = i

    while j < N:

        if A[j] < A[min_j]:

            min_j = j

        j += 1

    A[i], A[min_j] = A[min_j], A[i]

    if i != min_j :
        s_count += 1

    i += 1

s = ''

for x in A:

    s = s + str(x) + ' '

print(s.rstrip())
print(s_count)

Submission status: Accepted

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

_ = input()
SelectionSort([int(i) for i in input().split()])

Submission status: Accepted

Solution code:
def s_sort(l):
    q = len(l)
    count = 0
    for i in range(q):
        minv = i
        for j in range(i+1, q):
            if l[j] < l[minv]:
                minv = j
        if minv != i:
            l[i], l[minv] = l[minv], l[i]
            count += 1
    print(' '.join(map(str, l)))
    print(count)


if __name__ == '__main__':
    N = int(input())
    ali = list(map(int, input().split()))
    s_sort(ali)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
swap_counter = 0
for i in range(N):
    min_temp = i
    for j in range(i, N, 1):
        if A[j] < A[min_temp]:
            min_temp = j
    if i < min_temp:
        A[i], A[min_temp] = A[min_temp], A[i]
        swap_counter += 1
A_str = [str(a) for a in A]
result = ' '.join(A_str)
print(result)
print(swap_counter)

Submission status: Accepted

Solution code:
def selection_sort(nums, n):
    c = 0

    for i in range(n):
        minj = i

        for j in range(i, n):
            if nums[j] < nums[minj]:
                minj = j

        if i != minj:
            nums[i], nums[minj] = nums[minj], nums[i]
            c += 1

    return (c, nums)

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

    c, nums = selection_sort(nums, n)

    print(" ".join([str(x) for x in nums]))
    print(c)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

# selectionSortの処理
count = 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:
        count += 1
print(*A)
print(count)

Submission status: Accepted

Solution code:
def selection_sort(lis, l):
    times = 0
    for i in range(0, l - 1):
        minj = i
        minj_cp = minj
        for j in range(i, l):
            if lis[j] < lis[minj]:
                minj = j
        if minj_cp != minj:
            times += 1
        ele = lis[i]
        lis[i] = lis[minj]
        lis[minj] = ele
    return times

inputs = []
while True:
    try:
        inputs.append(input())
    except(EOFError):
        break

ln = int(inputs[0])
li = list(map(int, inputs[1].split()))

t = selection_sort(li, ln)

print(*li)
print(t)

Submission status: Accepted

Solution code:
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
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
print(*A)
print(cnt)

Submission status: Accepted

Solution code:
def selections(N):
    count = 0
    for i in range(len(N)):
        mini = i
        for j in range(i+1, len(N)):
            if N[mini] > N[j]:
                mini = j
        if i != mini:
            N[mini], N[i] = N[i], N[mini]
            count += 1
    c = 1
    for i in N:
        print(i, end='')
        if c < len(N):
            print(' ', end='')
            c += 1
    print('')
    print(count)
     
n = int(input())
numbers = list(map(int, input().split()))
 
selections(numbers)

Submission status: Accepted

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

def selectionSort():
  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
  return cnt

cnt = selectionSort()
print(" ".join(map(str, a)))
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
s = s.split(" ")
count = 0
for i in range(n):
    s[i] = int(s[i])
for i in range(n):
    minj = i
    for j in range(i+1,n):
        if s[j] < s[minj]:
            minj = j
    if i!= minj:
        v = s[i]
        s[i] = s[minj]
        s[minj] = v
        count += 1
for i in range(n-1):
    print(s[i],end = " ")
print(s[n-1])
print(count)

Submission status: Accepted

Solution code:
# Selection sort
def selection_sort(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
        if not i == minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            counter += 1
    return counter
N = int(input())
A = [int(i) for i in input().split(' ')]
c = selection_sort(A,N)
print(' '.join(list(map(str, A))))
print(c)

Submission status: Runtime Error

Solution code:
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):lens
            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

Submission status: Runtime Error

Solution code:

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)

Submission status: Runtime Error

Solution code:
#include<iostream>

int selection_sort(int A[], int N) {
  int i, j, tmp, sw = 0, min_i;
  for (i = 0; i < N-1; i++) {
    min_i = i;
    for (j = i+1; j < N; j++) {
      if (A[j] < A[min_i]) min_i = j;
    }
    tmp = A[i];
    A[i] = A[min_i];
    A[min_i] = tmp;
    if (i != min_i) sw++;
  }
  return sw;
}

int main() {
  int A[100], i, N, sw;

  std::cin >> N;
  for (i = 0; i < N; i++) std::cin >> A[i];

  sw = selection_sort(A, N);
  
  for (i = 0; i < N; i++) {
    if (i > 0) std::cout << ' ';
    std::cout << A[i];
  }
  std::cout << std::endl;
  std::cout << sw << std::endl;

  return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
ef 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()

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input()))
c = 0
min = 9
for i in range(0,n):
    minj = i
    for j in range(i+1,n):
        if a[j] < a[minj]:
            minj = j
    a[i],a[minj] = a[minj],a[j]
    c += 1
print(*a)
print(c)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input()))
c = 0
min = 9
for i in range(0,n):
    minj = i
    for j in range(i+1,n):
        if a[j] < a[minj]:
            minj = j
    a[i],a[minj] = a[minj],a[j]
    c += 1
    
print(*a)
print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
 coding: utf-8

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

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

if __name__ == '__main__':

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

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

if __name__ == '__main__':

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

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

if __name__ == '__main__':
	main()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
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

Submission status: Runtime Error

Solution code:
def show_list(a):
    for x in a:
        print x,
    print

def selection_sort(a,n):
    count=0
    for i in xrange(1,10):
        minj = i
        for j in xrange(i,n):
            if a[j]<a[minj]:
                minj = j
        tmp = a[i]
        a[i]=a[minj]
        a[minj]=tmp
        count+=1
    show_list(a)
    print count


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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-


def selection_sort(A, N):
    for i in xrange(N):
        minj = i
        change = 0
        for j in xrange(i, N):
            if A[j] < A[minj]:
                minj = j
                temp = A[minj]
                A[minj] = A[j]
                A[j] = temp
                change += 1


if __name__ == "__main__":
    N = input()
    A = map(int, raw_input().split())
    result, change = selection_sort(A, N)
    print ' '.join(map(str, result))
    print change

Submission status: Runtime Error

Solution code:
length = int(input())
targ = [int(n) for n in input().split(' ')]
ans = 0
for l in range(length):
    value = l
    for init in range(l + 1,length):
        if targ[value] > targ[init]:
            value = init
    if value != l:
        disp = targ[l]
        targ[l] = targ[value]
        targ[value] = disp
        ans += 1
print(' '.join([str(n) for n in targ]))
print(ans)''

Submission status: Runtime Error

Solution code:
N = int(input())

A = [int(x) for x in input().split()]
num_c = 0
for i in (0, N):
    minj = i
    for j in (i, N):
        if A[j] < A[minj]:
            minj = j
    A[i], A[minj] = A[minj], A[j]
    num_c += 1

print((" ").join(str(x) for x in A))
print(num_c)

Submission status: Runtime Error

Solution code:
N = int(input())

A = [int(x) for x in input().split()]
num_c = 0
for i in (0, N):
    minj = i
    for j in (i, N):
        if A[j] < A[minj]:
            minj = j
    A[i], A[minj] = A[minj], A[i]
    num_c += 1

print((" ").join(str(x) for x in A))
print(num_c)

Submission status: Runtime Error

Solution code:
# insertionSort                                                
# divide list into ordered part and part wait to sort          
# select one from part wait to sort and insert into ordered par
t                                                              
global r, signals                                              
r, signals = 0, False                                          
def insertionSort(A):                                          
    global r, signals                                          
    # Get length of A                                          
    l = len(A)                                                 
    for i in range(l):                                         
        # Selected i-th element to swap from 0 to n            
        v = A[i]                                               
        # j is point to tail of order                          
        j = i - 1                                              
        # Move forward, Control order of sorted                
        while j >= 0 and A[j] > v:                             
            A[j+1] = A[j]                                      
            j -= 1                                             
            signals = True                                     
        A[j+1] = v                                             
        r += 1 if signals else 0                               
        signals = False                                        
    return A                                                   
                                                               
raw_input()                                                    
res, l = "", 0                                                 
for i in insertionSort(map(int, raw_input().split())):         
    res += (" " if l != 0 else "") + str(i)                    
    l += 1                                                     
print res, "\n", r

Submission status: Runtime Error

Solution code:
# insertionSort                                                
# divide list into ordered part and part wait to sort          
# select one from part wait to sort and insert into ordered part                             
def insertionSort(A):                                          
    # Get length of A                                          
    l, r = len(A), 0                                                 
    for i in range(l):                                         
        # Selected i-th element to swap from 0 to n            
        v = A[i]                                               
        # j is point to tail of order                          
        j = i - 1                                              
        # Move forward, Control order of sorted                
        while j >= 0 and A[j] > v:                             
            A[j+1] = A[j]                                      
            j -= 1                                             
        A[j+1] = v
        r += (0 if i != j else 1)        
    return A                                                   
                                                               
raw_input()                                                    
res, l = "", 0                                                 
for i in insertionSort(map(int, raw_input().split())):         
    res += (" " if l != 0 else "") + str(i)                    
    l += 1                                                     
print res
print r

Submission status: Runtime Error

Solution code:
#3.4

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

swapCount = 0
for i in range(0, N):
    minIndex = 1
    for j in range(i + 1, N):
        if a[j] < a[minIndex]:
            minIndex = j
    
    if i != minIndex:
        tmp = a[i]
        a[i] = a[minIdex]
        a[minIndex] = tmp
        swapCount += 1

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

Submission status: Runtime Error

Solution code:
#3.4

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

swapCount = 0
for i in range(0, N):
    minIndex = 1
    for j in range(0, N):
        if a[j] < a[minIndex]:
            minIndex = j
    
    if i != minIndex:
        tmp = a[i]
        a[i] = a[minIdex]
        a[minIndex] = tmp
        swapCount += 1

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().strip().split()))
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]
print(' '.join(map(str,a)))
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=input()
lst=input().split()
cnt = 0
for i in range(0, len(lst)):
    m = i
    for j in range(i, len(lst)):
        if lst[m] > lst[j]:
            m = j
    if m != i:
        lst[i], lst[m] = lst[m], lst[i]
        cnt+=1

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

Submission status: Runtime Error

Solution code:
n=input()
lst=input().split()

cnt = 0
for i in range(0, len(lst)):
    m = i
    for j in range(i, len(lst)):
        if lst[m] > lst[j]:
            m = j
    if m != i:
        lst[i], lst[m] = lst[m], lst[i]
        cnt+=1

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

c = 0

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

print(" ".join([str(x) for x in a]))
print(c)

Submission status: Runtime Error

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

def print_list(A):
    for a in A[:-1]:
        print ("%d "%a, end="")
    print(A[-1])

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:
            v = A[i]
            A[i] = A[minj]
            A[minj] = v
            count += 1
    return A, count
        
A_sorted, c = BubbleSort(A, N)

print_list(A_sorted)
print(c)

Submission status: Runtime Error

Solution code:
def selectionsort(A, N):
	count = 0
	for i in range(N):
		min_a = min(A[i:])
		min_index = A.index(min_a)
		A[i], A[min_index] = min_a, A[i]
		if (A[i] != A[min_index]): count += 1
	return count

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

	c = selectionsort2(data, n)
	print(*data)
	print(c)

if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
def SelectionSort(A):
    for i in range(len(A)):
        minj = i
        for j in range(i, range(A)):
            if A[j] < A[minj]:
                minj = j
        A[i], A[minj] = A[minj], A[i]


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

SelectionSort(A)

Submission status: Runtime Error

Solution code:
def SelectionSort(A):
    count = 0
    for i in range(len(A)):
        minj = i
        for j in range(i, range(A)):
            if A[j] < A[minj]:
                minj = j
        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)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(i) for i in input().split(" ")]
x=0
for i in range(n):
    mi=i
    for j in range(i,n):
        if a[j] < a[mi]:
            mi = j
    if i != mi:
        x+=1
        a[i],a[mi]=a[mi],[i]

print(" ".join([str(i) for i in a]))
print(x)

Submission status: Runtime Error

Solution code:
def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]
    exchange_count = 0

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

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

if __name__ == '__main__' :
    main()

Submission status: Runtime Error

Solution code:
def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]
    exchange_count = 0

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

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

if __name__ == '__main__' :
    main()

Submission status: Runtime Error

Solution code:
def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]
    exchange_count = 0

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

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

if __name__ == '__main__' :
    main()

Submission status: Runtime Error

Solution code:
def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]
    exchange_count = 0

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

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

if __name__ == '__main__' :
    main()

Submission status: Runtime Error

Solution code:
def selectionSort(A, N):
    s = 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]
        s += 1
    t = str(A[0])
    for i in range(1,N):
        t = t + " " + str(A[i])
    print(t)
    print(s)

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

slectionSort(a, n)