Problem:


Bubble Sort

Write a program of the Bubble Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:

BubbleSort(A)
1 for i = 0 to A.length-1
2     for j = A.length-1 downto i+1
3         if A[j] N, the number of elements in the sequence.

In the second line, N elements of the sequence are given separated by spaces 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

5
5 3 2 4 1

Sample Output 1

1 2 3 4 5
8

Sample Input 2

6
5 2 4 6 1 3

Sample Output 2

1 2 3 4 5 6
9



Sample input:
5
5 3 2 4 1


Sample output:
1 2 3 4 5
8

Submission status: Wrong Answer

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

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

def bubble_sort(A, n):
    print_list(A)
    flg = 1 #逆の隣接要素が存在する
    i = 0
    while flg:
        flg = 0
        for j in range(n-1, i+1, -1):
            if A[j-1] > A[j]:
                A[j-1], A[j] = swap(A[j-1], A[j])
                flg = 1
                print_list(A)
        i += 1

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

bubble_sort(A, n)

Submission status: Wrong Answer

Solution code:
data = [int(i) for i in input().split(' ')]
count = 0
flag = 1
while flag==1:
  flag=0
  for i in range(1,len(data)):
    k = len(data)-i
    if data[k] < data[k-1]:
      a = data[k]
      b = data[k-1]
      data[k] = b
      data[k-1] = a
      flag=1
      count += 1

print(count)
print(' '.join([str(dt) for dt in data]))

Submission status: Wrong Answer

Solution code:
bit=[0 for i in xrange(200)]
n=int(raw_input().strip())
class dig:
    def __init__(self,val,id):
        self.val=val
        self.id=id
    def __gt__(self,other):
        return self.val<other.val


def sum(i):
    s=0
    i=int(i)
    while i>0:
        s+=bit[i]
        i-=i&(-i)
    return s
def add(i,x):
    i=int(i)
    while i<=n:
        bit[i]+=x
        i+=i&-i



lst=map(int,raw_input().strip().split())
vals=[]
lens=len(lst)
for i in xrange(lens):
    vals.append(dig(lst[i],i+1))
vals.sort()
ans=0
for i in vals:
    #print i.val,i.id
    ans+=sum(i.id)
    add(i.id,1)
lst.sort()
print " ".join(str(pp) for pp in lst)
print ans

Submission status: Wrong Answer

Solution code:
def sort(A, exchange):
    for i in range(0, len(A) - 1):
        if modify_order(A, i) == 0:
            break

def modify_order(A, i):
    exchange = 0
    for j in  range(len(A) - 1, i, -1):
        if A[j - 1] > A[j]:
            A[j - 1], A[j] = A[j], A[j - 1]
            exchange = exchange + 1

n = int(input())
s = list(map(int, input().strip().split(' ')))
e = 0
sort(s, e)
print(s)
print(e)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = input('Please input the number of elements: ')
    N = int(N)
    array = list(map(int,  input('Please input the array: ').split()))
    for i in range(N):
        print(' '.join(map(str, array)))
        for j in range(N-1, i, -1):
            if array[j] < array[j-1]:
                array[j], array[j-1] = array[j-1], array[j]
    print(' '.join(map(str, array)))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = input('Please input the number of elements: ')
    N = int(N)
    array = list(map(int,  input('Please input the array: ').split()))
    cnt = 0
    for i in range(N):
        # print(' '.join(map(str, array)))
        for j in range(N-1, i, -1):
            if array[j] < array[j-1]:
                array[j], array[j-1] = array[j-1], array[j]
                cnt += 1
    print(' '.join(map(str, array)))
    print(cnt)

Submission status: Wrong Answer

Solution code:
N = input('Please input the number of elements: ')
N = int(N)
array = list(map(int, input('Please input the array: ').split()))
cnt = 0
for i in range(N):
        # print(' '.join(map(str, array)))
    for j in range(N-1, i, -1):
        if array[j] < array[j-1]:
            array[j], array[j-1] = array[j-1], array[j]
            cnt += 1
print(' '.join(map(str, array)))
print(cnt)

Submission status: Wrong Answer

Solution code:
N = input('Please input the number of elements: ')
N = int(N)
array = list(map(int,  input('Please input the array: ').split()))
cnt = 0
for i in range(N):
    # print(' '.join(map(str, array)))
    for j in range(N-1, i, -1):
        if array[j] < array[j-1]:
            array[j], array[j-1] = array[j-1], array[j]
            cnt += 1
print(' '.join(map(str, array)))
print("%d" % (cnt))

Submission status: Wrong Answer

Solution code:
def show(nums):
    for i in range(len(nums)):
        if i != len(nums) - 1:
            print(nums[i],end=' ')
        else:
            print(nums[i])

def bubbleSort(A,N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in range(N-1,0,-1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
    show(A)
    print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int, input().strip().split(' ')))
e = int()
e = 0
flag = True
while flag:
        flag = False
        for i in range(n - 1, 0, -1):
            if s[i] < s[i - 1]:
                s[i - 1], s[i] = s[i], s[i - 1]
                e = e + 1
                flag = True

for i in range(0 , len(s)):
    if i != 4:
        print(s[i], end=" ")
    else:
        print(s[i])

print(e)

Submission status: Wrong Answer

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

print(A[::-1],count,sep='\n')

Submission status: Wrong Answer

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

print(*A[::-1],count,sep='\n')

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

for i in range(n):
    for j in range(i + 1, n - i):
        if (nums[j] < nums[i]):
            temp = nums[j]
            nums[j] = nums[i]
            nums[i] = temp
            count += 1

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

Submission status: Wrong Answer

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

for i in range(n):
#    for j in range(i + 1, n - i):
    for j in range(i + 1, n):
        if (nums[j] < nums[i]):
            temp = nums[j]
            nums[j] = nums[i]
            nums[i] = temp
            count += 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = map(int,input().split())
flag = False
while flag:
    for j in range(n-1,1,-1):
        if(a[j] < a[j-1]):
            a[j],a[j-1] = a[j-1],a[j]
            flag = 1

Submission status: Wrong Answer

Solution code:
n = int(input())
a = map(int,input().split())
flag = False
c = 0
while flag:
    for j in range(n-1,1,-1):
        if(a[j] < a[j-1]):
            a[j],a[j-1] = a[j-1],a[j]
            flag = 1
            c += 1
print(*a)
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = map(int,input().split())
flag = False
c = 0
while flag:
    flag = False
    for j in range(n-1,1,-1):
        if(a[j] < a[j-1]):
            a[j],a[j-1] = a[j-1],a[j]
            flag = 1
            c += 1
print(*a)
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
flag = True
c = 0
while flag:
    flag = False
    for j in range(n-1,1,-1):
        if(a[j] < a[j-1]):
            a[j],a[j-1] = a[j-1],a[j]
            flag = 1
            c += 1
print(*a)
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
flag = True
c = 0
while flag:
    flag = False
    for j in range(n-1,1,-1):
        if(a[j] < a[j-1]):
            a[j],a[j-1] = a[j-1],a[j]
            flag = True
            c += 1
print(*a)
print(c)

Submission status: Wrong Answer

Solution code:
def main():
	c = 0
	n = input()
	a = map(int, input_raw().split())

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

	print(c)

Submission status: Wrong Answer

Solution code:
while True:
    try:

        num = input().split(' ')
        num1 = int(num[0])
        num2 = int(num[1])
        sum_number = num1 + num2
        import math

        ans = int(math.log10(sum_number) + 1)
        print(ans)

    except:
        break

Submission status: Wrong Answer

Solution code:
def bubbleSort(list_, n):
    list_ = list_[:]
    count = 0
    for i in xrange(n):
        for j in xrange(n-1, i, -1):
            if list_[j] < list_[j - 1]:
                list_[j], list_[j - 1] = list_[j - 1], list_[j]
                count += 1

    return list_, count

n = input()
nums = map(int, raw_input().split())
sorted_, count = bubbleSort(nums, n)
print sorted_
print count

Submission status: Wrong Answer

Solution code:
n=raw_input()
a=list(map(int,raw_input().split()))
print sorted(a)

Submission status: Wrong Answer

Solution code:
def bubble(A,N):
	flag=1
	cnt=0
	while flag==1:
		flag=0
		for j in range(1,N):
			if A[j]<A[j-1]:
				k=A[j-1]
				A[j-1]=A[j]
				A[j]=k
				flag=1
				cnt+=1
	return A,cnt
n=int(raw_input())			
list=map(int,raw_input().split())
list,cnt=bubble(list,n)
print list
print cnt-1

Submission status: Wrong Answer

Solution code:
N=int(input())

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

count=0
i=N-1

while i>=0:
	j=0
	while j<=i:
		if A[N-1-j]<A[N-2-j]:
			(A[N-1-j],A[N-2-j])=(A[N-2-j],A[N-1-j])
			count+=1
		j+=1
	i-=1


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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
A = list(map(int,s.split()))
flag = 1

while(flag == 1):
    for k in range(0,len(A)-1):
        print(A[k],end=" ")
    print(A[len(A)-1])
    flag = 0
    for j in range(n-1,0,-1):
        if A[j] < A[j-1]:
            tmp = A[j]
            A[j] = A[j-1]
            A[j-1] = tmp
            flag = 1

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

Submission status: Wrong Answer

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

print " ".join(map(str,num_list))
c = 0
flag = 1
while flag:
    flag =0
    for j in range(N-1,0,-1):
        if num_list[j] < num_list[j-1]:
            a = num_list[j]
            num_list[j] = numlist[j-1]
            num_list[j-1] = a
            c += 1
            flag =1
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(" ")

flag = 1

c = 0
while flag == 1:
    flag = 0
    for j in reversed(range(1,len(A))):
        if A[j] < A[j-1]:
            a = A[j]
            b = A[j-1]
            A[j] = b
            A[j-1] = a
            flag = 1
            c += 1

print " ".join(A)
print c

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = raw_input().split(" ")
count = 0
flag = 1

while flag == 1:
    flag = 0
    for j in reversed(range(1, N)):
        if A[j] < A[j-1]:
            temp = A[j]
            A[j] = A[j-1]
            A[j-1] = temp
            count += 1
            flag = 1

print " ".join(A)
print count

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = raw_input().split(" ")
count = 0
flag = 1

i = 0
while flag == 1:
    flag = 0
    for j in reversed(range(i+1, N)):
        if A[j] < A[j-1]:
            temp = A[j]
            A[j] = A[j-1]
            A[j-1] = temp
            count += 1
            flag = 1
    i += 1
    
print " ".join(A)
print count

Submission status: Wrong Answer

Solution code:
import sys

lines = sys.stdin.readlines()

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

flag = 1

c = 0
i = 0
while flag == 1:
    flag = 0
    for j in reversed(range(i+1,len(A))):
        if A[j] < A[j-1]:
            a = A[j]
            b = A[j-1]
            A[j] = b
            A[j-1] = a
            flag = 1
            c += 1
    i += 1

print " ".join(A)
print c

Submission status: Wrong Answer

Solution code:
def input_data():
    num = raw_input()
    array = []
    array = num.strip().split(" ")
    return array


def main():
    n = raw_input()
    count = 0
    array = input_data()
    flag = True
    while flag:
        flag = False
        for j in reversed(xrange(1, int(n))):
            if array[j] < array[j - 1]:
                v = array[j]
                array[j] = array[j - 1]
                array[j - 1] = v
                flag = True
                count += 1
    print " ".join(array)
    print str(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def input_data():
    num = raw_input()
    array = []
    array = num.strip().split(" ")
    return array


def main():
    n = raw_input()
    count = 0
    array = input_data()
    flag = True
    i = 0
    while flag:
        flag = False
        for j in reversed(xrange(i + 1, int(n))):
            if array[j] < array[j - 1]:
                v = array[j]
                array[j] = array[j - 1]
                array[j - 1] = v
                flag = True
                count += 1
                print array
        i += 1
    print " ".join(array)
    print str(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def input_data():
    num = raw_input()
    array = []
    array = num.strip().split(" ")
    array = map(int, array)
    return array


def main():
    n = raw_input()
    count = 0
    array = input_data()
    flag = True
    i = 0
    while flag:
        flag = False
        for j in reversed(xrange(i + 1, int(n))):
            if array[j] < array[j - 1]:
                v = array[j]
                array[j] = array[j - 1]
                array[j - 1] = v
                flag = True
                count += 1
                print array
        i += 1
    array = map(str, array)
    print " ".join(array)
    print str(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def bubble_sort(List):
	cnt=0
	l=len(List)
	for i in range(l):
		for j in range(l-1,i,-1):
			if List[j]<List[j-1]:
				temp=List[j]
				List[j]=List[j-1]
				List[j-1]=temp
				cnt+=1
	return cnt
def main():
	N=input()
	N_List=map(str,raw_input().split())
	cnt=bubble_sort(N_List)
	print(" ".join(N_List))
	print(cnt)

if __name__=='__main__':
	main()

Submission status: Wrong Answer

Solution code:
def bubbleSort(nums, length):
  count = 0
  for i in xrange(0, length - 1):
    for j in xrange(i + 1, length):
      if nums[i] > nums[j]:
        tmp = nums[i]
        nums[i] = nums[j]
        nums[j] = tmp
        count += 1
  return [nums, count]

length = int(raw_input())
nums = map(int, raw_input().split())
ans = bubbleSort(nums, length)
print " ".join(map(str, ans[0]))
print ans[1]

Submission status: Wrong Answer

Solution code:
def BubbleSort(A,n):
    for i in range(n):
        for j in range(n-1,i,-1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
    return A

n = int(input())
A = [int(input()) for i in range(n)]

print (BubbleSort(A,n))

Submission status: Wrong Answer

Solution code:
def BubbleSort(A,n):
    count = 0
    for i in range(n):
        for j in range(n-1,i,-1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                count += 1
    return (str(A) + '\n' + str(count))

n = int(input())
A = [int(input()) for i in range(n)]

print (BubbleSort(A,n))

Submission status: Wrong Answer

Solution code:
def BubbleSort1(A,n):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in range(n-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count += 1
    return A, n


n = int(input())
A = [int(input()) for i in range(n)]

ans, count =  (BubbleSort1(A,n))
ans = list(map(str,ans))

print (" ".join(ans))
print (count)

Submission status: Wrong Answer

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


def bubble_sort(A, N):
    cnt = 0
    flag = True
    while(flag):
        flag = False
        for i in range(N-1, 0, -1):
            if(A[i-1] > A[i]):
                tmp = A[i-1]
                A[i-1] = A[i]
                A[i] = tmp
                cnt += 1
                flag = True
    B = list(map(str, A))
    print(" ".join(B))
    print(cnt)

print(*A)
bubble_sort(A, N)

Submission status: Wrong Answer

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


def bubble_sort(A, N):
    cnt = 0
    flag = True
    while(flag):
        flag = False
        for i in range(N-1, 0, -1):
            if(A[i-1] > A[i]):
                tmp = A[i-1]
                A[i-1] = A[i]
                A[i] = tmp
                cnt += 1
                flag = True
    print(cnt)
    B = list(map(str, A))
    print(" ".join(B))

print(*A)
bubble_sort(A, N)

Submission status: Wrong Answer

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


def bubble_sort(A, N):
    cnt = 0
    flag = True
    while(flag):
        flag = False
        for i in range(N-1, 0, -1):
            if(A[i-1] > A[i]):
                tmp = A[i-1]
                A[i-1] = A[i]
                A[i] = tmp
                cnt += 1
                flag = True

    print(" ".join(list(map(str, A))))
    print(cnt)

print(*A)
bubble_sort(A, N)

Submission status: Wrong Answer

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


def bubble_sort(A, N):
    cnt = 0
    flag = True
    while(flag):
        flag = False
        for i in range(N-1, 1, -1):
            if(A[i-1] > A[i]):
                tmp = A[i-1]
                A[i-1] = A[i]
                A[i] = tmp
                cnt += 1
                flag = True

    print(" ".join(list(map(str, A))))
    print(cnt)

print(*A)
bubble_sort(A, N)

Submission status: Wrong Answer

Solution code:
def selection_sort(A, N):
    m = 0
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if(A[minj] > A[j]):
                minj = j
        if(minj != i):
            m += 1
            A[minj], A[i] = A[i], A[minj]

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

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

selection_sort(A, N)

Submission status: Wrong Answer

Solution code:
def selection_sort(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(minj != i):
            cnt += 1
            A[minj], A[i] = A[i], A[minj]

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

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

selection_sort(A, N)

Submission status: Wrong Answer

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

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

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

selection_sort(A, N)

Submission status: Wrong Answer

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

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

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

selection_sort(A, N)

Submission status: Wrong Answer

Solution code:
def selection_sort(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[minj] != A[i]):
            cnt += 1
            A[minj], A[i] = A[i], A[minj]

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

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

Submission status: Wrong Answer

Solution code:
def selection_sort(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(minj != i):
            cnt += 1
            A[minj], A[i] = A[i], A[minj]

    print(" ".join(list(map(str, A))))
    print(cnt)

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

Submission status: Wrong Answer

Solution code:
def selection_sort(A, N):
    count = 0
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if(A[minj] > A[j]):
                minj = j
        if(A[minj] != A[i]):
            count += 1
            A[minj], A[i] = A[i], A[minj]

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

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

Submission status: Wrong Answer

Solution code:
# def selection_sort(A, N):
#     count = 0
#     for i in range(0, N):
#         minj = i
#         for j in range(i, N):
#             if(A[minj] > A[j]):
#                 minj = j
#         if(A[minj] != A[i]):
#             count += 1
#             A[minj], A[i] = A[i], A[minj]

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

# N = int(input())
# A = list(map(int, input().split()))
# selection_sort(A, N)
def selection_sort(ary, n):
    count = 0
    for i in range(n):
        minj = i
        for j in range(i, n):
            if ary[minj] > ary[j]:
                minj = j
        if ary[minj] != ary[i]:
            ary[minj], ary[i] = ary[i], ary[minj]
            count += 1
    print(*ary)
    print(count)
 
n = int(input())
selection_sort(list(map(int, input().split())), n)

Submission status: Wrong Answer

Solution code:
# def selection_sort(A, N):
#     count = 0
#     for i in range(0, N):
#         minj = i
#         for j in range(i, N):
#             if(A[minj] > A[j]):
#                 minj = j
#         if(A[minj] != A[i]):
#             count += 1
#             A[minj], A[i] = A[i], A[minj]

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

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

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

Submission status: Wrong Answer

Solution code:
# def selection_sort(A, N):
#     count = 0
#     for i in range(0, N):
#         minj = i
#         for j in range(i, N):
#             if(A[minj] > A[j]):
#                 minj = j
#         if(A[minj] != A[i]):
#             count += 1
#             A[minj], A[i] = A[i], A[minj]

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

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

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

Submission status: Wrong Answer

Solution code:
def selection_sort(A, N):
    count = 0
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if(A[minj] > A[j]):
                minj = j
            if(minj != i):
                count += 1
                A[minj], A[i] = A[i], A[minj]

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

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

Submission status: Wrong Answer

Solution code:
def selection_sort(A, N):
    count = 0
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if(A[minj] > A[j]):
                minj = j
        if(minj != i):
            count += 1
            A[minj], A[i] = A[i], A[minj]
        

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

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

Submission status: Wrong Answer

Solution code:
def selection_sort(A, N):
    count = 0
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if(A[minj] > A[j]):
                minj = j
        if(minj != i):
            count += 1
            A[minj], A[i] = A[i], A[minj]

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

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

Submission status: Wrong Answer

Solution code:
def selection_sort(A, N):
    count = 0
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if(A[minj] > A[j]):
                minj = j
        if(minj != i):
            count += 1
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            # A[minj], A[i] = A[i], A[minj]

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
data = [int(i) for i in input().split(' ')]

def bubble_sort(raw_list):
    n_list = len(raw_list)
    n_swap = 0
    sorted_i = 0
    flag = True
    while flag:
        flag = False
        for j in reversed(range(sorted_i, n_list)):
            if raw_list[j] < raw_list[j-1]:
                raw_list[j-1], raw_list[j] = raw_list[j], raw_list[j-1]
                n_swap += 1
                flag = True
        sorted_i += 1
    print(' '.join([str(i) for i in raw_list]))
    print(n_swap)
        
bubble_sort(data)

Submission status: Wrong Answer

Solution code:
def trace(a,n) :
    li=[]
    for i in xrange(n):
        li.append(str(a[i]))
    print(" ".join(li))
    
def bubblesort(a,n):
    flag=1
    ct=0
    while flag:
        flag=0
        for i in xrange(n-1,0,-1):
            if a[i]<a[i-1]:
                keep=a[i-1]
                a[i-1]=a[i]
                a[i]=keep
                ct+=1
                flag=1
    return ct
n=input()
a=map(str,raw_input().split())
ct=bubblesort(a,n)
trace(a,n)

Submission status: Wrong Answer

Solution code:
def trace(a,n) :
    li=[]
    for i in xrange(n):
        li.append(str(a[i]))
    print(" ".join(li))
    
def bubblesort(a,n):
    flag=1
    ct=0
    while flag:
        flag=0
        if n==0:
            break
        else :
            for i in xrange(n-1,0,-1):
                if a[i]<a[i-1]:
                    keep=a[i-1]
                    a[i-1]=a[i]
                    a[i]=keep
                    ct+=1
                    flag=1
    return ct
n=input()
a=map(str,raw_input().split())
ct=bubblesort(a,n)
trace(a,n)
print(ct)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
i = 0
flag = 1
while flag:
    flag = 0
    for j in range(N-1, i, -1):
        if A[j] < A[j-1]:
            A_j = A[j]
            A[j] = A[j-1]
            A[j-1] = A_j
            flag = 1
            i += 1
print " ".join(map(str, A))
print i

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
i = 0
flag = 1
while flag:
    flag = 0
    for j in range(N-1, 0, -1):
        if A[j] < A[j-1]:
            A_j = A[j]
            A[j] = A[j-1]
            A[j-1] = A_j
            flag = 1
    i += 1
print " ".join(map(str, A))
print i

Submission status: Wrong Answer

Solution code:
#coding: UTF-8

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

for i in range(a - 1):
    for j in range(a-1, i,-1):
        if N[j] < N[j - 1]:
            tmp = N[j]
            N[j] = N[j - 1]
            N[j - 1] = tmp

for i in range(a - 1):
    print(N[i],end=' ')
print(N[a-1]);
print(c);

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

def bubble_sort(a,n):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in reversed(xrange(1,n)):
            if a[j] < a[j-1]:
                tmp = a[j]
                a[j] = a[j-1]
                a[j-1] = tmp
                count+=1
                flag = True
    show_list(a)
    print count
def main():
    n = input()
    a = map(int,raw_input().split())
    print a
    bubble_sort(a,n)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def show_list(a):
    ans = ""
    for x in a:
        ans += str(x)
    print ans

def bubble_sort(a,n):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in reversed(xrange(1,n)):
            if a[j] < a[j-1]:
                tmp = a[j]
                a[j] = a[j-1]
                a[j-1] = tmp
                count+=1
                flag = True
    show_list(a)
    print count
def main():
    n = input()
    a = map(int,raw_input().split())
    print a
    bubble_sort(a,n)

if __name__ == '__main__':
    main()