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: Wrong Answer

Solution code:
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]
    c+=1
print(*a)
print(c)

Submission status: Wrong Answer

Solution code:
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):
    print_list(A)
    replace_num = 0
    for i in range(0, n):
        minj = find_minj(A, i, n)
        A[i], A[minj] = swap(A[i], A[minj])
        replace_num += 1
    print(replace_num)

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

selection_sort(A, n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# inputList = list(map(int, '''6
# 5 6 4 2 1 3'''.split()))
# N = inputList.pop(0)


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

Submission status: Wrong Answer

Solution code:
# inputList = list(map(int, '''6
# 5 6 4 2 1 3'''.split()))
# N = inputList.pop(0)


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

    formatting(A)
    print(count - 1)



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

selectionSort(inputList, N)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
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]
    count+=1
print(*l)
print(count)

Submission status: Wrong Answer

Solution code:
def inserrtionsort(l,n):
  for i in range(1,n):
    print(" ".join(l))
    v=l[i]
    j=i-1
    while int(v)<int(l[j]) and j>=0:
      l[j+1]=l[j]
      j-=1
    l[j+1]=v
  print(" ".join(l))
m=int(input())
n=list(input().split())
inserrtionsort(n,m)

Submission status: Wrong Answer

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]
        c+=1
    print("".join(l))
    print(c)
n=int(input())
l=list(input())
selectionsort(l,n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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
        a[i], a[tmp] = a[tmp], a[i]
        ans += 1

    print(*a)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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[i]
    c += 1
    
print(*a)
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
def  select_sort(buff):
	k = len(buff)
	for i in xrange(k - 1):
		min = buff[i]
		n = i
		for j in xrange(i + 1, k):
			if buff(j) < min:
				min = buff[j]
				n = j
		buff[n] = buff[j]
		buff[i] = min

N = int(raw_input())
buff = map(int, raw_input().split(' '))
select_sort(buff)

Submission status: Wrong Answer

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, N)
	print ' '.join(map(str, A))

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
num = raw_input()
num_list = raw_input().split()
num_list = map(int, num_list)
count = 0 

def bubble_sort(num_list, count):
    flag = True
    i = 0 
    while flag:
        flag = False
        for j in range(len(num_list)-1, i, -1):
            if num_list[j-1] > num_list[j]:
                temp = num_list[j]
                num_list[j] = num_list[j-1]
                num_list[j-1] = temp
                count += 1
                flag = True
        i += 1
    return count

count = bubble_sort(num_list, count)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
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
            count += 1
    A[i], A[min_j] = A[min_j], A[i]
print " ".join(map(str, A))
print count

Submission status: Wrong Answer

Solution code:
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 A[j] < A[minj]:
            minj = j
    if A[i] != A[minj]:
        a = A[i]
        b = A[minj]
        A[i] = b
        A[minj] = a
        count += 1

print " ".join(A)
print count

Submission status: Wrong Answer

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 A[j] < A[minj]:
            minj = j

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

print " ".join(A)
print count

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
num_list = map(int, raw_input().split())
c = 0
flag =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
            flag = 1
    c += flag
    num_list[i], num_list[minj] = num_list[minj], num_list[i]
print " ".join(map(str,num_list))
print c

Submission status: Wrong Answer

Solution code:
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 A[j] < 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

Submission status: Wrong Answer

Solution code:
num = raw_input()
num_list = raw_input().split()
num_list = map(int, num_list)

def selection_sort(num_list, count):
    flag = True
    i = 0 
    while flag:
        flag = False
        for j in range(i, len(num_list)):
            if num_list[i] > num_list[j]:
                temp = num_list[j]
                num_list[j] = num_list[i]
                num_list[i] = temp
                count += 1
                flag = True
        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

Submission status: Wrong Answer

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

def main():
    N = int(raw_input())
    A = map(int,raw_input())
    newA, count = selectionSort(A, N)
    print ' '.join(map(str,newA))
    print N
    return 0

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def selectionSort(A, N):
    for i in range(N - 1):
        minValue = 100
        minIndex = 0
        for j in range(i, N):
            if A[j] < minValue:
                minValue = A[j]
                minIndex = j
        temp = A[i]
        A[i] = minValue
        A[minIndex] = temp

    for i in range(N):
        print A[i],
    print
    print N - 1

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

selectionSort(A, N)

Submission status: Wrong Answer

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

def selection_sort(a,n):
    count=0
    for i in xrange(n):
        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: Wrong Answer

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

def selection_sort(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:  
            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: Wrong Answer

Solution code:
def selection_sort(array):
    for i in range(len(array)):
        j = min(range(i, len(array)), key=lambda x: array[x])
        array[i], array[j] = array[j], array[i]


class SegmentTree(object):
  
    def __init__(self, size, op=min, init=float("inf")):
        self.size = 1
        self.op = op
        self.init = init
        while self.size < size:
            self.size *= 2
        self.data = [init] * (self.size*2+2)
  
    def update(self, idx, value):
        k = idx + self.size - 1
        self.data[k] = value
        while k > 0:
            k = (k - 1) // 2
            self.data[k] = self.op(self.data[k*2+1], self.data[k*2+2])

    def __getitem__(self, val):
        return self.data[(self.size)+val]
  
    def find(self, start, end):
        def query(k, left, right):
            if right <= start or end <= left:
                return self.init
            if start <= left and right <= end:
                return self.data[k]
            vl = query(k*2+1, left, (left+right)//2)
            vr = query(k*2+2, (left+right)//2, right)
            return self.op(vl, vr)
        return query(0, 0, self.size)

        
def swap_count(array):
    count = 0
    rmq = SegmentTree(len(array), op=min, init=(float("inf"), float("inf")))
    for i, v in enumerate(array):
        rmq.update(i, (v, i))
    for i in range(len(array)):
        vi, _ = rmq[i]
        vj, j = rmq.find(i, len(array))
        if i == j:
            continue
        count += 1
        rmq.update(i, (vj, i))
        rmq.update(j, (vi, j))
    return count

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    count = swap_count(A)
    print(*sorted(A))
    print(swap_count(A))

Submission status: Wrong Answer

Solution code:
def selection_sort(array):
    for i in range(len(array)):
        j = min(range(i, len(array)), key=lambda x: array[x])
        array[i], array[j] = array[j], array[i]


class SegmentTree(object):

    def __init__(self, size, op=min, init=float("inf")):
        self.size = 1
        self.op = op
        self.init = init
        while self.size < size:
            self.size *= 2
        self.data = [init] * (self.size*2+2)

    def update(self, idx, value):
        k = idx + self.size - 1
        self.data[k] = value
        while k > 0:
            k = (k - 1) // 2
            self.data[k] = self.op(self.data[k*2+1], self.data[k*2+2])

    def __getitem__(self, val):
        return self.data[(self.size-1)+val]

    def find(self, start, end):
        def query(k, left, right):
            if right <= start or end <= left:
                return self.init
            if start <= left and right <= end:
                return self.data[k]
            vl = query(k*2+1, left, (left+right)//2)
            vr = query(k*2+2, (left+right)//2, right)
            return self.op(vl, vr)
        return query(0, 0, self.size)


def swap_count(array):
    count = 0
    rmq = SegmentTree(len(array), op=min, init=(float("inf"), float("inf")))
    for i, v in enumerate(array):
        rmq.update(i, (v, -i))
    for i in range(len(array)):
        vi, _ = rmq[i]
        vj, idx = rmq.find(i, len(array))
        j = -idx
        if rmq[i] <= rmq[j]:
            continue
        count += 1
        rmq.update(i, (vj, -i))
        rmq.update(j, (vi, -j))
    return count

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    count = swap_count(A)
    print(*sorted(A))
    print(swap_count(A))

Submission status: Wrong Answer

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, 1):
            if A[j] < A[minj]:
                minj = j
        temp = A[minj]
        A[minj] = A[i]
        A[i] = temp
        change += 1
    return (A, change)


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: Wrong Answer

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


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


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: Wrong Answer

Solution code:
n = int(input())
A = input().split(' ')
count = 0

for i in range(0, n):
    minj = i

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

    (A[i], A[minj]) = (A[minj], A[i])

print(" ".join(A))
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = 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
            count += 1

    (A[i], A[minj]) = (A[minj], A[i])

print(" ".join(A))
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = 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

    (A[i], A[minj]) = (A[minj], A[i])
    count += 1

print(" ".join(A))
print(count)

Submission status: Wrong Answer

Solution code:
def main():
  element_num = int(input())
  elements = [int(s) for s in input().split()]
  swap_count = 0

  for i in range(0, element_num - 1):
    max_val = elements[i + 1]
    max_index = i + 1
    for j in range(i + 1, element_num):
      if max_val < elements[j]:
        max_val = elements[j]
        max_index = j
    if elements[i] > elements[max_index]:
      elements[i], elements[max_index] = elements[max_index], elements[i]
      swap_count += 1

  print(' '.join(list(map(str, elements))))
  print(swap_count)

  return 0


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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(targ)
print(ans)

Submission status: Wrong Answer

Solution code:
# selection sort
N = int(input())
A = [int(i) for i in input().split()]

cnt = 0

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

print(' '.join([str(i) for i in A]))
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
cnt = 0

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

print(li)
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

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

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

    print(cnt)
    
def main():
    n = int(sys.stdin.readline().strip())
    data = sys.stdin.readline().strip().split(' ')
    nums = [int(i) for i in data]
    selection_sort(nums, n)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

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

        nums[i], nums[minj] = nums[minj], nums[i]
        cnt += 1

    print(cnt)
    
def main():
    n = int(sys.stdin.readline().strip())
    data = sys.stdin.readline().strip().split(' ')
    nums = [int(i) for i in data]
    selection_sort(nums, n)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

def selection_sort(nums, n):
    cnt = 0
    
    for i in range(n):
        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:
            cnt += 1

    print(cnt)
    
def main():
    n = int(sys.stdin.readline().strip())
    data = sys.stdin.readline().strip().split(' ')
    nums = [int(i) for i in data]
    selection_sort(nums, n)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
length = int(input())
eles = [int(l) for l in input().split()]
times = 0

for i in range(length-1):
    _min = i
    for j in range(i, length):
        if eles[j] < eles[_min]:
            _min = j
    eles[i], eles[_min] = eles[_min], eles[i]
    times += 1

print(*eles)
print(times)

Submission status: Wrong Answer

Solution code:
length = int(input())
eles = [int(l) for l in input().split()]
times = 0

for i in range(length-1):
    _min = i
    for j in range(i, length):
        if eles[j] < eles[_min]:
            _min = j
    if i != _min:
        eles[i], eles[_min] = eles[_min], eles[i]
        times += 1

print(times)
print(*eles)

Submission status: Wrong Answer

Solution code:
#coding:UTF-8
def BS(N,A):
    for i in range(N):
        for j in reversed(range(i+1,N)):
            if int(A[j][1:])<int(A[j-1][1:]):
                swap=A[j]
                A[j]=A[j-1]
                A[j-1]=swap
    return A

def SS(N,A):
    for i in range(N):
        minj=i
        for j in range(i,N):
            if int(A[j][1:]) < int(A[minj][1:]):
                minj=j
        
        swap=A[i]
        A[i]=A[minj]
        A[minj]=swap
    return A

def Stable(A1,A2):
    ans="Stable"
    for i in range(len(A1)):
        if A1[i][1:]==A2[i][1:] and A1[i][:1]!=A2[i][:1]:
            ans="Not stable"
    return ans

def SS2(N,A,B):
    print(A,B)
    A1=BS(N,A)
    print(" ".join(A1))
    print("Stable")
    A2=SS(N,B)
    print(" ".join(A2))
    print(Stable(A1,A2))

if __name__=="__main__":
    N=int(input())
    a=input()
    A=a.split(" ")
    B=a.split(" ")
    SS2(N,A,B)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# encoding: utf-8


class Solution:
    @staticmethod
    def selection_sort():
        # write your code here
        array_length = int(input())
        unsorted_array = [int(x) for x in input().split()]

        count = 0
        for i in range(array_length):
            min_j = i
            for j in range(i, array_length):
                if unsorted_array[j] < unsorted_array[min_j]:
                    min_j = j
            unsorted_array[i], unsorted_array[min_j] = unsorted_array[min_j], unsorted_array[i]
            count += 1

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


if __name__ == '__main__':
    solution = Solution()
    solution.selection_sort()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def select_sort(array):
    N = len(array)
    count = 0
    
    for i in range(N - 1):
        min_i = array.index(min(array[i:]))
        if i != min_i:
            count += 1
        array[i], array[min_i] = array[min_i], array[i]
        
    return array, count

n = int(input())
array = [int(i) for i in input().split()]
result = select_sort(array)

print(*result[0])
print(result[1])

Submission status: Wrong Answer

Solution code:
def selectionSort(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
        A[i], A[minj] = A[minj], A[i]
        swap_count += 1
    return swap_count

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

Submission status: Wrong Answer

Solution code:
def selectionSort(A, N):
    swap_count = 0
    if N < 2:
        return swap_count
    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]
        swap_count += 1
    return swap_count

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

Submission status: Wrong Answer

Solution code:
def selection(A,n):
  count = 0
  for i in range(0,n-1):
    min = i
    for j in range(i,n):
      if(A[j] < A[min]):
        min = j
    if(min!=i):
      A[i], A[min] = A[min], A[i]
      count+=1
  print(count)

def printList(A):
  print(" ".join(str(x) for x in A))

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

Submission status: Wrong Answer

Solution code:
cnt = 0
n = int(input())
lst = list(map(int, input().split()))
for i in range(n):
    m = i
    for j in range(i, n):
        if lst[j] < lst[m]:
            m = j
    lst[i], lst[m] = lst[j], lst[j-1]
    cnt += 1
print(*lst)
print(cnt)

Submission status: Wrong Answer

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

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

count = selectionSort(A, N)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
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]
        count += 1
    return (count)

if __name__ == '__main__':
    n = int(input())
    data = [int(i) for i in range(n)]
    result = selectionSort(data,n)
    print(" ".join(map(str,data)))
    print(result)