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 bubbleSort(A, N):
    flag = 1
    count = 0
    while flag == 1:
        flag = 0
        for i in range(1, N)[::-1]:
            if A[j] < A[j - 1]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp
                flag = 1
                count += 1
    print(A)
    print(count)

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

bubbleSort(A, n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    flag = True
    count = 0 # ?????¢??°
    i = 0 # ?????????????????????????????????????????????
    while flag :
        flag = False # ?????????????????????????????£???????????????
        for i in reversed(range(i, n)) :
            if nums[i-1] > nums[i] :
                nums[i-1], nums[i] = nums[i], nums[i-1]
                count += 1
                flag = True
        i += 1

    nums_str = [str(i) for i in nums]
    print(" ".join(nums_str))
    print(count)

if __name__ == '__main__' :
    main()

Submission status: Wrong Answer

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

    flag = True
    count = 0
    i = 0
    while flag :
        flag = False
        for i in reversed(range(i, n)) :
            if nums[i-1] > nums[i] :
                nums[i-1], nums[i] = nums[i], nums[i-1]
                count += 1
                flag = True
        i += 1

    nums_str = [str(i) for i in nums]
    print(" ".join(nums_str))
    print(count)

if __name__ == '__main__' :
    main()

Submission status: Wrong Answer

Solution code:
def bubbleSort(A, N):
    t = 0
    flag = 0
    while flag == 0:
        flag = 1
        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 = 0
                t += 1
n = int(input())
a = [int(i) for i in input().split()]

print(bubbleSort(a, n))

Submission status: Wrong Answer

Solution code:
def bubbleSort(A, N):
    t = 0
    flag = 0
    while flag == 0:
        flag = 1
        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 = 0
                t += 1
    print(A)
    print(t)

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

bubbleSort(a, n)

Submission status: Wrong Answer

Solution code:
#coding: UTF-8

import sys
import math

class Algo:
  @staticmethod
  def bubble(r, n):
    flag = 1
    count = 0
    while flag:
      flag = 0
      for j in range(n-1, 0, -1):
        if r[j] < r[j-1]:
          r[j], r[j-1] = r[j-1], r[j]
          count += 1
          flag = 1

    for v in r:
      if v==r[len(r)-1]:
        print(v)
      else:
        print(v, " ", sep="", end="")
    print(count)

N = int(input())
R= list(map(int, input().split()))
Algo.bubble(R, N)

Submission status: Wrong Answer

Solution code:
#coding: UTF-8

import sys
import math

class Algo:
  @staticmethod
  def bubbleSort(r, n):
    flag = 1
    count = 0
    while flag:
      flag = 0
      for j in range(n-1, 0, -1):
        if r[j] < r[j-1]:
          r[j], r[j-1] = r[j-1], r[j]
          count += 1
          flag = 1

    for v in r:
      if v==r[len(r)-1]:
        print(v)
      else:
        print(v, " ", sep="", end="")
    print(count)

N = int(input())
R= list(map(int, input().split()))
Algo.bubbleSort(R, N)

Submission status: Wrong Answer

Solution code:
def bubbleSort(A, N):
    flag = True
    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
    print(A)
    print(count)


arr_length = int(input())
arr_num = [int(i) for i in input().split(" ")]

bubbleSort(arr_num, arr_length)

Submission status: Wrong Answer

Solution code:
def bubble_sort(A):
    swap_cnt = 0
    for i in range(len(A)):
        for j in range(len(A) - 1, i + 1, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                swap_cnt += 1
    return A, swap_cnt


n = int(input())
A = list(map(int, input().split()))
A, swap_cnt = bubble_sort(A)
print(' '.join(map(str, A)))
print(swap_cnt)

Submission status: Wrong Answer

Solution code:
import sys

def bubble_sort(x):
    if(len(x) == 1):
        count = 1
    else:
        count = 0
    for i in range(0,len(l)-1):
        for j in range(i+1,len(l)):
            if(x[i] > x[j]):
                count += 1
                temp = x[i]
                x[i] = x[j]
                x[j] = temp
    for data in x:
        print data,
    print '\n',count


l = []
for input in sys.stdin:
    l.append(input)
l = l[1:]
l = l[0].split()
for i in range(0,len(l)):
    l[i] = int(l[i])
bubble_sort(l)

Submission status: Wrong Answer

Solution code:
import sys

def bubble_sort(x):
    count = 0
    for i in range(0,len(l)-1):
        for j in range(i+1,len(l)):
            if(x[i] > x[j]):
                count += 1
                temp = x[i]
                x[i] = x[j]
                x[j] = temp
    for data in x:
        print data,
    print
    print count


l = []
for input in sys.stdin:
    l.append(input)
l = l[1:]
l = l[0].split()
for i in range(0,len(l)):
    l[i] = int(l[i])
bubble_sort(l)

Submission status: Wrong Answer

Solution code:
def bubble(l):
	N = len(l)
	flag = 1

	while flag:
		flag = 0
		for j in range(N - 1, 1 - 1, -1):
			if l[j] < l[j - 1]:
				l[j], l[j - 1] = l[j - 1], l[j]
				flag = 1

	return l


if __name__ == '__main__':
	n = int(input())
	l = input().split()

	for i in range(n):
		l[i] = int(l[i])

	l = bubble(l)
	count = 0
	leng = len(l)
	for i in l:
		count += 1
		if count < leng:
			print(i, end =' ')
		else:
			print(i)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input().split(' ')

flag=1
m=0

while flag:
	flag=0
	for j in range(n-1,0,-1):
		if s[j]<s[j-1]:
			a=s[j]
			s[j]=s[j-1]
			s[j-1]=a
			m+=1
			flag=1

print(' '.join(s))
print(m)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input().split(' ')

flag=1
m=0

while flag:
	flag=0
	for j in range(n-1,1,-1):
		if s[j]<s[j-1]:
			a=s[j]
			s[j]=s[j-1]
			s[j-1]=a
			m+=1
			flag=1

print(' '.join(s))
print(m)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input().split(' ')

flag=1
m=0

while flag:
    flag=0
    for j in range(1,n):
        j=n-j
        if s[j]<s[j-1]:
            a=s[j]
            s[j]=s[j-1]
            s[j-1]=a
            m+=1
            flag=1

print(' '.join(s))
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
*A, = map(int, input().split())
ans = 0
k = 0
while k < N - 1 :
    i = N - 1
    while i > k :
        if A[i] < A[i-1] :
            A[i], A[i-1] = A[i-1], A[i]
        i = i - 1
        ans = ans + 1
    k = k + 1
print(*A)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(n-2):
 for j in range(n-1,i,-1):
  if a[j-1]>a[j]:a[j-1],a[j]=a[j],a[j-1]
 c+=1
print(*a)
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=c=0
for i in range(n-2):
 for j in range(n-1,i,-1):
  if a[j-1]>a[j]:a[j-1],a[j]=a[j],a[j-1];b=1
 if b>0:c+=1;b=0
print(*a)
print(c)

Submission status: Wrong Answer

Solution code:
count = int(input());
data = [int(n) for n in input().split(" ")];

def bubble_sort(data):
    show(data);
    count = len(data);
    for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j] < data[j - 1]:
                temp = data[j];
                data[j] = data[j - 1];
                data[j - 1] = temp;
        show(data);

def show(data):
    print(" ".join(str(n) for n in data));

bubble_sort(data);

Submission status: Wrong Answer

Solution code:
def insertionSort(A,input_num):
    for i in range(input_num):
        v = A[i]
        j = i - 1
        while(j >= 0 and A[j] > v):
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        print(*A)
        
input_num = int(input())
A = list(map(int, input().split()))

insertionSort(A,input_num)

Submission status: Wrong Answer

Solution code:
def insertionSort(A,input_num):
    for i in range(input_num):
        v = A[i]
        j = i - 1
        while(j >= 0 and A[j] > v):
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        print(*A)
        print(i)
        
input_num = int(input())
A = list(map(int, input().split()))

insertionSort(A,input_num)

Submission status: Wrong Answer

Solution code:
def main():

    n = int(input())
    a = []
    for _ in range(n):
        a.append(int(input()))
    
    count = 0

    flag = True
    while flag:
        flag = False
        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 = True
                count += 1
    
    print(a)
    print(count)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#バブルソート
def BubbleSort(A,N):
    #繰り返し判定
    flag = 1
    #ソート回数カウンター
    count = 0
    while flag:
        flag = 0
        for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                tmp = A[i]
                A[i] = A[i- 1]
                A[i-1] = tmp
                flag = 1
                count = count +1
                print(' '.join(map(str,A)))
    print(count)
            
N = int(input())
A = input()
A = list(map(int,A.split()))
BubbleSort(A,N)

Submission status: Wrong Answer

Solution code:
# -*- coding: UTF-8 -*-
#Bubble Sort

#標準入力から
N = int(input()) #要素数
A = list(map(int,input().split())) #ソート対象（スペース区切り→配列に展開）

#print('input')
#print(N)
#print(A)

flag = 1
i = 0
cnt = 0

#Sort処理（自分メモ：flagが0になったらループを抜ける）
while flag:
    flag = 0
    for j in reversed(range(i+1,N)):
        if A[j] < A[j-1]:
            tmp = A[j-1]
            A[j-1] = A[j]
            A[j] = tmp
            flag = 1
            cnt += 1
    i += 1

#print('output')
print(A)
print(cnt)

Submission status: Wrong Answer

Solution code:
def bubbleSort(A, N): # N 個の要素を含む 0-オリジンの配列 A
    print(A)
    A = list(map(int, A.split()))
    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] を交換
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
    print(count)

N = int(input())
A = input()
bubbleSort(A, N)

Submission status: Wrong Answer

Solution code:
def bubbleSort(A, N): # N 個の要素を含む 0-オリジンの配列 A
    print(A)
    A = list(map(int, A.split()))
    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] を交換
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
            count += 1
    print(count)

N = int(input())
A = input()
bubbleSort(A, N)

Submission status: Wrong Answer

Solution code:
def bubbleSort(A, N): # N 個の要素を含む 0-オリジンの配列 A
    A = list(map(int, A.split()))
    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] を交換
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
    print(A)
    print(count)

N = int(input())
A = input()
bubbleSort(A, N)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
def bubblesort(list):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(n-1,0,-1):
            if a[i]<a[i-1]:
                a[i],a[i-1] = a[i-1],a[i]
                flag = 1
                count+=1
    print(count)
bubblesort(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
def bubblesort(list):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(n-1,0,-1):
            if list[i]<list[i-1]:
                list[i],list[i-1] = list[i-1],list[i]
                flag = 1
                count+=1
    print(count)
bubblesort(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
def bubblesort(list):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(n-1,0,-1):
            if list[i]<list[i-1]:
                list[i],list[i-1] = list[i-1],list[i]
                flag = 1
                count+=1
    return(count)
bubblesort(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
flag = 1
count = 0
while flag:
    flag = 0
    for i in range(n-1,0,-1):
        if a[i]<a[i-1]:
            a[i],a[i-1] = a[i-1],a[i]
            flag = 1
            count+=1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def bubble_sort(ls):
    flag=True
    i=0
    ch=0
    while flag:
        flag = False
        for j in reversed(range(i+1,len(ls))):
            if ls[j] < ls[j-1]:
                ls[j],ls[j-1] = ls[j-1],ls[j]
                flag = True
                ch += 1
        i += 1
    return ch

if __name__ == "__main__":
    ls=[]
    n=int(input())
    ls = list(map(int,input().split()))
    ch=bubble_sort(ls)
    for i in ls:
        if i == ls[-1]:
            print(i)
        else:
            print(i,end=" ")
    print(ch)

Submission status: Wrong Answer

Solution code:
def bubble_sort(ls):
    flag=True
    i=0
    ch=0
    while flag:
        flag = False
        for j in reversed(range(i+1,len(ls))):
            if ls[j] < ls[j-1]:
                ls[j],ls[j-1] = ls[j-1],ls[j]
                flag = True
                ch += 1
        i += 1
    return ch

if __name__ == "__main__":
    ls=[]
    n=int(input())
    ls = list(map(int,input().split()))
    ch=bubble_sort(ls)
    for i in range(len(ls)):
        if i == len(ls):
            print(ls[i])
        else:
            print(ls[i],end=" ")
    print(ch)

Submission status: Wrong Answer

Solution code:
def bubbleSort(a,n):
    flag = 1
    c=0
    while(flag):
        flag = 0
        for i in reversed(range(1,len(a))):
            if(a[i] < a[i-1]):
                a[i],a[i-1] = a[i-1],a[i]
                c += 1
                flag = 1
    return [a,c]

n = int(input())
a = list(map(int,input().split(' ')))
sa , c = bubbleSort(a, n)
print("{}\n{}".format(sa,c))

Submission status: Wrong Answer

Solution code:
# リストの宣言
A = []

# 入力の最初の行に、数列の長さを表す整数 N が与えられます。
# 2 行目に、N 個の整数が空白区切りで与えられます。
LENGTH =int(input())
A = input().split()

# 変数
N = 0
M = LENGTH - 1
CHANGE = 0

# BubbleSort(A)
#  for i = 0 to A.length-1
while N <= LENGTH -1 :
    M = LENGTH - 1
    print ('N=',N)
#      for j = A.length-1 downto i+1
    while M >= N + 1:
        print  ('-M=',M)
#          if A[j] < A[j-1]
        if A[M] < A[M-1] :
            tmp = A[M-1]
            A[M-1] = A[M]
            A[M] = tmp
            CHANGE += 1
        M -= 1
    N += 1

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

Submission status: Wrong Answer

Solution code:
# リストの宣言
A = []

# 入力の最初の行に、数列の長さを表す整数 N が与えられます。
# 2 行目に、N 個の整数が空白区切りで与えられます。
LENGTH =int(input())
A = input().split()

# 変数
N = 0
M = LENGTH - 1
CHANGE = 0

# BubbleSort(A)
#  for i = 0 to A.length-1
while N <= LENGTH -1 :
    M = LENGTH - 1
#    print ('N=',N)
#      for j = A.length-1 downto i+1
    while M >= N + 1:
#       print  ('-M=',M)
#          if A[j] < A[j-1]
        if A[M] < A[M-1] :
            tmp = A[M-1]
            A[M-1] = A[M]
            A[M] = tmp
            CHANGE += 1
        M -= 1
    N += 1

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

Submission status: Wrong Answer

Solution code:
# リストの宣言
A = []

# 入力の最初の行に、数列の長さを表す整数 N が与えられます。
# 2 行目に、N 個の整数が空白区切りで与えられます。
LENGTH =int(input())
A = input().split()

# 変数
N = 0
M = LENGTH - 1
CHANGE = 0


while N <= LENGTH -1 :
    M = LENGTH - 1
    while M >= N + 1:
        if A[M] < A[M-1] :
            tmp = A[M-1]
            A[M-1] = A[M]
            A[M] = tmp
            CHANGE += 1
        M -= 1
    N += 1

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

Submission status: Wrong Answer

Solution code:
# リストの宣言
A = []

# 入力の最初の行に、数列の長さを表す整数 N が与えられます。
# 2 行目に、N 個の整数が空白区切りで与えられます。
LENGTH =int(input())
A = input().split()

# 変数
N = 0
M = LENGTH - 1
CHANGE = 0

# BubbleSort(A)
#  for i = 0 to A.length-1
while N <= LENGTH -1 :
    M = LENGTH - 1
#    print ('N=',N)
#      for j = A.length-1 downto i+1
    while M >= N + 1:
#       print  ('-M=',M)
#          if A[j] < A[j-1]
        if A[M] < A[M-1] :
            tmp = A[M-1]
            A[M-1] = A[M]
            A[M] = tmp
            CHANGE += 1
        M -= 1
    N += 1

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

Submission status: Wrong Answer

Solution code:
# リストの宣言
A = []

# 入力の最初の行に、数列の長さを表す整数 N が与えられます。
# 2 行目に、N 個の整数が空白区切りで与えられます。
LENGTH =int(input())
A = input().split()

# 変数
N = 0
M = LENGTH - 1
CHANGE = 0

# BubbleSort(A)
#  for i = 0 to A.length-1
while N <= LENGTH -1 :
    M = LENGTH - 1
#    print ('N=',N)
#      for j = A.length-1 downto i+1
    while M >= N + 1:
#       print  ('-M=',M)
#          if A[j] < A[j-1]
        if A[M] < A[M-1] :
            tmp = A[M-1]
            A[M-1] = A[M]
            A[M] = tmp
            CHANGE += 1
        M -= 1
    N += 1

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input().split()
flag=True;count=0
while flag:
    flag=False
    for i in range(1,n):
        if a[i]<a[i-1]:
            key=a[i]
            a[i]=a[i-1]
            a[i-1]=key
            count+=1
            flag=True
print(' '.join(a))
print(count)

Submission status: Wrong Answer

Solution code:
def BS(A, N):
    A = list(map(int, A.split()))
    flag = 1
    count = 0 
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                unk = A[j]
                A[j] = A[j-1]
                A[j-1] = unk
                flag = 1
                count = count +1
    print(" ".join(map(str,A)))
    print(count)

Submission status: Wrong Answer

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

flag = True
judge = True

while flag:
    for i in range(n-1,0,-1):
        if a[i] < a[i - 1]:
            a[i],a[i - 1] = a[i - 1], a[i] #swap
    print(' '.join(map(str,a)))
    if sorted(a) == a: flag = False

Submission status: Wrong Answer

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

if __name__ == '__main__':
    N = int(raw_input())
    l = map(int, raw_input().split())
    cnt = 0
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if l[j] < l[minj]:
                minj = j
        if i != minj:
            l[i], l[minj] = l[minj], l[i]
            cnt += 1
    print ' '.join(map(str, l))
    print cnt

Submission status: Wrong Answer

Solution code:
def bubble_sort(a):
    res = 0
    for i in range(len(a)):
        for j in range(len(a)-1, i, -1):
            if a[j-1] > a[j]:
                a[j], a[j-1] = a[j-1], a[j]
                res += 1
    return res

def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = bubble_sort(a)
    print(a)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = [int(input()) for i in range(N)]

swap_cnt = 0
i = 0
while True:
    swap_flg = False
    for j in range(N - 1, i + 1, -1):
        if (arr[j] < arr[j - 1]):
            arr[j], arr[j - 1] = arr[j - 1], arr[j]
            swap_cnt += 1
            swap_flg = True
    if (not(swap_flg)):
        break

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = [int(input()) for i in range(N)]

swap_cnt = 0
swap_flg = True
i = 0
while swap_flg:
    swap_flg = False
    for j in range(N - 1, i + 1, -1):
        if (arr[j] < arr[j - 1]):
            arr[j], arr[j - 1] = arr[j - 1], arr[j]
            swap_cnt += 1
            swap_flg = True

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = [int(input()) for i in range(N)]

swap_cnt = 0
swap_flg = True
i = 0
while swap_flg:
    swap_flg = False
    for j in range(N - 1, i + 1, -1):
        if (arr[j] < arr[j - 1]):
            arr[j], arr[j - 1] = arr[j - 1], arr[j]
            swap_cnt += 1
            swap_flg = True
    i += 1

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = [int(input()) for i in range(N)]

swap_cnt = 0
swap_flg = True
i = 0
while swap_flg:
    swap_flg = False
    for j in range(N - 1, i, -1):
        if (arr[j] < arr[j - 1]):
            arr[j], arr[j - 1] = arr[j - 1], arr[j]
            swap_cnt += 1
            swap_flg = True
    i += 1

Submission status: Wrong Answer

Solution code:
N = int(input())
l = input().split()
l = [int(s) for s in l]
for j in range(N):
    for i in range(N-1):
        if( l[i] < l[i+1]):
            l[i], l[i+1] = l[i+1], l[i]
for i in range(0,len(l)-1):
    print(l[i],end=' ')
print(l[N-1])

Submission status: Wrong Answer

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

if __name__ == '__main__':
    print(" ".join(map(str, A)))
    for i in range(N-1):
        for j in range(N-1, i, -1):
            if A[j-1] > A[j]:
                A[j-1], A[j] = A[j], A[j-1]
    print(" ".join(map(str, A)))

Submission status: Wrong Answer

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

if __name__ == '__main__':
    print(" ".join(map(str, A)))
    for i in range(N):
        for j in range(N-1, i, -1):
            if A[j-1] > A[j]:
                A[j-1], A[j] = A[j], A[j-1]
    print(" ".join(map(str, A)))

Submission status: Wrong Answer

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

if __name__ == '__main__':
    for i in range(N):
        for j in range(N-1, i, -1):
            if j > 0 and A[j-1] > A[j]:
                A[j-1], A[j] = A[j], A[j-1]
    print(" ".join(map(str, A)))

Submission status: Wrong Answer

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

if __name__ == '__main__':
    flag = True
    cnt = 0
    while flag:
        flag = False
        for i in range(N-1, 1, -1):
            if A[i] < A[i-1]:
                A[i], A[i-1] = A[i-1], A[i]
                flag = True
    print(" ".join(map(str, A)))
    print(cnt)

Submission status: Wrong Answer

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

if __name__ == '__main__':
    flag = True
    cnt = 0
    while flag:
        flag = False
        for i in range(N-1, 1, -1):
            if A[i] < A[i-1]:
                A[i], A[i-1] = A[i-1], A[i]
                cnt += 1
                flag = True
    print(" ".join(map(str, A)))
    print(cnt)

Submission status: Wrong Answer

Solution code:
input()
arr = list(map(int, input().split()))
flag = False
count = 0
while not flag:
    flag = True
    for i in range(len(arr)-1):
        if arr[i] > arr[i+1]:
            count + 1
            flag = False
            t = arr[i+1]
            arr[i+1] = arr[i]
            arr[i] = t  
print(" ".join(map(str, arr)))
print(count)

Submission status: Wrong Answer

Solution code:
import sys
def main():
    for line in sys.stdin:
        line=line.split()
        line=map(int,line)
        A.append(line)
    N=A[0][0]
    B=A[1]
    n=0
    for i in range (N):
        for k in range(N-i-1):
            print k
            j=(N-2)-k
            if B[j]>B[j+1]:
                C=B[j]
                B[j]=B[j+1]
                B[j+1]=C
                n=n+1
    E=map(str,B)
    D=" ".join(E)
    print n
    print D

Submission status: Wrong Answer

Solution code:
import sys
def main():
    for line in sys.stdin:
        line=line.split()
        line=map(int,line)
        A.append(line)
    N=A[0][0]
    B=A[1]
    n=0
    for i in range (N):
        for k in range(N-i-1):
            print k
            j=(N-2)-k
            if B[j]>B[j+1]:
                C=B[j]
                B[j]=B[j+1]
                B[j+1]=C
                n=n+1
    E=map(str,B)
    D=" ".join(E)
    print D
    print n

Submission status: Wrong Answer

Solution code:
import sys
def main():
    #A=[[5],[5,3,2,4,1]]
    for line in sys.stdin:
        line=line.split()
        line=map(int,line)
        A.append(line)
    N=A[0][0]
    B=A[1]
    n=0
    for i in range (N):
        for k in range(N-i-1):
            j=(N-2)-k
            if B[j]>B[j+1]:
                C=B[j]
                B[j]=B[j+1]
                B[j+1]=C
                n=n+1
    E=map(str,B)
    D=" ".join(E)
    print n
    print D

Submission status: Wrong Answer

Solution code:
import sys
def main():
    #A=[[5],[5,3,2,4,1]]
    for line in sys.stdin:
        line=line.split()
        line=map(int,line)
        A.append(line)
    N=A[0][0]
    B=A[1]
    n=0
    for i in range (N):
        for k in range(N-i-1):
            j=(N-2)-k
            if B[j]>B[j+1]:
                C=B[j]
                B[j]=B[j+1]
                B[j+1]=C
                n=n+1
    E=map(str,B)
    D=" ".join(E)
    D.strip(D)
    print n
    print D

Submission status: Wrong Answer

Solution code:
import sys
#import os
def main():
    A=[]
    for line in sys.stdin:
        line=line.split()
        line=map(int,line)
        A.append(line)
    N=A[0][0]
    B=A[1]
    n=0
    for i in range (N):
        for k in range(N-i-1):
            j=(N-2)-k
            if B[j]>B[j+1]:
                C=B[j]
                B[j]=B[j+1]
                B[j+1]=C
                n=n+1
    E=map(str,B)
    D=" ".join(E)
    D.strip(D)
    print D 
    print n

Submission status: Wrong Answer

Solution code:
import sys
import os
def main():
    #fi=open("test1.txt","r")
    #sys.stdin=fi
    B=[]
    K=input()
    for line in range (K):
        line=raw_input()
        line=map(int,line)
        B.append(line)
    n=0
    for i in range (N):
        for k in range(N-i-1):
            j=(N-2)-k
            if B[j]>B[j+1]:
                C=B[j]
                B[j]=B[j+1]
                B[j+1]=C
                n=n+1
    E=map(str,B)
    D=" ".join(E)
    D.strip(D)
    print D 
    print n

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
i=int(raw_input())
n=map(int, raw_input().split())
ans=0
chk=10
#サンプルリスト
n=[2,5,3,1,7,9,10,4,6,8]
#n=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
#リストの長さ、要素の個数分の繰り返し回数設定
for m in range(len(n)):
    for j in range(len(n)-1, m, -1):
        if n[j]<n[j-1]:
            n[j],n[j-1]=n[j-1],n[j]
            ans+=1
#        print ans
    if ans==chk: break
    chk=ans
print ' '.join(map(str,n))
print ans

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
i=int(raw_input())
n=map(int, raw_input().split())
ans=0
chk=10
#サンプルリスト
n=[2,5,3,1,7,9,10,4,6,8]
#n=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
#リストの長さ、要素の個数分の繰り返し回数設定
#リストの長さ、要素の個数分の繰り返し回数設定
for m in range(len(n)):
    for j in range(len(n)-1, m, -1):
        if n[j]<n[j-1]:
            n[j],n[j-1]=n[j-1],n[j]
            ans+=1
#        print ans
    if ans==chk: break
    chk=ans
print ' '.join(map(str,n))
print ans

Submission status: Time Limit Exceeded

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


class Solution:
    """
    @param prices: Given an integer array
    @return: Maximum profit
    """

    @staticmethod
    def swap(a, b):
        a, b = b, a
        return a, b

    def bubble_sort(self):
        # write your code here
        array_length = int(input())
        unsorted_array = [int(x) for x in input().split()]

        flag = 1
        count = 0
        while flag:
            flag = 0
            for j in range(array_length - 1, 0, -1):
                if unsorted_array[j] < unsorted_array[j - 1]:
                    self.swap(unsorted_array[j], unsorted_array[j - 1])
                    flag = 1
                    count += 1
        print(" ".join(map(str, unsorted_array)))
        print(str(count))


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

Submission status: Time Limit Exceeded

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

def bubble(A, N):
    count = 0
    flag = True
    while flag == True:
        for j in range(N-1, 0, -1):
            flag = False
            if A[j] < A[j - 1]:
                A[j -1],A[j] = A[j], A[j - 1]
                count += 1
                flag = True
    print(" ".join(map(str, A)))
    print(count)

bubble(A, N)