ZhenlongDai/ACPR huggingface dataset:
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
def inputInline():
    N=int(input())
    numbers=list(map(int,input().split(" ")))
    return numbers
def bubbleSort(list):
    N=len(list)
    count=0
    flag=True
    while flag:
        flag=False
        for i in range(N-1):
            if list[i]>list[i+1]:
                temp=list[i]
                list[i]=list[i+1]
                list[i+1]=temp
                flag=True
                count+=1
    return (list,count)
result=bubbleSort(inputInline())
print(result[0])
print(result[1])

Failing test case input:
6
0 1 0 9 3 0

Expected output:
0 0 0 1 3 9
5


Actual output:
[0, 0, 0, 1, 3, 9]
5


Fixed submission (verdict: Accepted):
def inputInline():
    N=int(input())
    numbers=list(map(int,input().split(" ")))
    return numbers
def bubbleSort(list):
    N=len(list)
    count=0
    flag=True
    while flag:
        flag=False
        for i in range(N-1):
            if list[i]>list[i+1]:
                temp=list[i]
                list[i]=list[i+1]
                list[i+1]=temp
                flag=True
                count+=1
    return (list,count)
result=bubbleSort(inputInline())
print(" ".join(list(map(str,result[0]))))
print(result[1])

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)

Failing test case input:
5
1 19 -3 -1 2

Expected output:
-3 -1 1 2 19
5


Actual output:

Fixed submission (verdict: Accepted):
def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag == 1:
        flag = 0
        for i in range(1, N)[::-1]:
            if A[i] < A[i - 1]:
                tmp = A[i]
                A[i] = A[i - 1]
                A[i - 1] = tmp
                flag = 1
                count += 1

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

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

bubbleSort(A, n)
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
n = input()
A = [int(i) for i in input().split(' ')]

def trace(A):
    for index, v in enumerate(A):
        print(v, end='')
        if index != len(A) - 1:
            print(' ', end='')
    print()

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

A, count = bubble_sort(A)
trace(A)
print(count)

Failing test case input:
6
2 1 -1 9 1 0

Expected output:
-1 0 1 1 2 9
9


Actual output:
-1 0 1 1 2 9
8


Fixed submission (verdict: Accepted):
n = int(input())
A = [int(i) for i in input().split(' ')]



def trace(A):
    for index, v in enumerate(A):
        print(v, end='')
        if index != len(A) - 1:
            print(' ', end='')
    print()

def bubble_sort(A, n):
    i = 0
    counter = 0
    while i <= n - 1:
        j = n - 1
        while j >= i + 1:
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                counter += 1
            j -= 1
        i += 1
    trace(A)
    print(counter)

bubble_sort(A, n)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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()


Failing test case input:
5
0 23 -3 2 0

Expected output:
-3 0 0 2 23
5


Actual output:
[-3, 0, 0, 2, 23]
5


Fixed submission (verdict: Accepted):
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(' '.join(map(str, a)))
    print(ans)

if __name__ == '__main__':
    main()

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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))


Failing test case input:
5
4 2 4 3 1

Expected output:
1 2 3 4 4
7


Actual output:
[1, 2, 3, 4, 4]
7


Fixed submission (verdict: Accepted):
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)
str = " ".join([str(i) for i in sa])
print("{}\n{}".format(str,c))
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)


Failing test case input:
5
1 38 -1 -1 2

Expected output:
-1 -1 1 2 38
5


Actual output:
-1 -1 1 2 38
10


Fixed submission (verdict: Accepted):
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]
            ans = ans + 1
        i = i - 1    
    k = k + 1
print(*A)
print(ans)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):


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

Failing test case input:
6
2 2 -1 4 0 0

Expected output:
-1 0 0 2 2 4
8


Actual output:
-1 0 0 2 2 4
0


Fixed submission (verdict: Accepted):


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]:
            c+=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);

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
n = int(input())
k = [int(i) for i in input().split()]

for i in range(n-1):
    for l in range(n-i-1):

        if k[n-2-l] > k[n-1-l]:
            v = k[n-1-l]
            k[n - 1 - l]=k[n-2-l]
            k[n - 2 - l]=v

        else:
            pass

print(' '.join(map(str, k)))

Failing test case input:
6
0 1 0 9 3 0

Expected output:
0 0 0 1 3 9
5


Actual output:
0 0 0 1 3 9


Fixed submission (verdict: Accepted):
n = int(input())
k = [int(i) for i in input().split()]
M = 0
for i in range(n-1):
    for l in range(n-i-1):

        if k[n-2-l] > k[n-1-l]:
            v = k[n-1-l]
            k[n - 1 - l]=k[n-2-l]
            k[n - 2 - l]=v
            M+=1
        else:
            pass

print(' '.join(map(str, k)))
print(M)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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])



Failing test case input:
5
1 83 -3 0 2

Expected output:
-3 0 1 2 83
5


Actual output:
83 2 1 0 -3


Fixed submission (verdict: Accepted):
N = int(input())
l = input().split()
l = [int(s) for s in l]
count = 0
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]
            count += 1
for i in range(0,len(l)-1):
    print(l[i],end=' ')
print(l[N-1])
print(count)
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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()

Failing test case input:
6
1 1 5 6 3 5

Expected output:
1 1 3 5 5 6
3


Actual output:
1 1 3 5 5 6
9


Fixed submission (verdict: Accepted):
def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]

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

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

if __name__ == '__main__' :
    main()

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)

Failing test case input:
6
3 1 -1 2 -1 -1

Expected output:
-1 -1 -1 1 2 3
10


Actual output:
3 1 -1 2 -1 -1
-1 -1 -1 1 2 3
10


Fixed submission (verdict: Accepted):
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)

bubble_sort(A, N)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
cnt = 0
n = int(input())
lst = list(map(int, input().split()))
for i in range(n):
    for j in range(n-1,i,-1):
        if lst[j] < lst[j-1]:
            lst[j-1:j+1] = lst[j], lst[j-1]
            cnt += 1
print(lst)
print(cnt)

Failing test case input:
5
4 39 -1 1 1

Expected output:
-1 1 1 4 39
6


Actual output:
[-1, 1, 1, 4, 39]
6


Fixed submission (verdict: Accepted):
cnt = 0
n = int(input())
lst = list(map(int, input().split()))
for i in range(n):
    for j in range(n-1,i,-1):
        if lst[j] < lst[j-1]:
            lst[j-1:j+1] = lst[j], lst[j-1]
            cnt += 1
print(*lst)
print(cnt)
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
n = int(input()) - 1
a = list(map(int, input().split()))

count = 0
flag  = 1

while flag:
    flag = 0
    for i in range( n, 0, -1 ):
        if a[i] < a[i-1]:
            t = a[i]
            a[i] = a[i-1]
            a[i-1] = t
            count += 1
            flag = 1

print(count)
print(*a)

Failing test case input:
6
-1 1 5 6 3 5

Expected output:
-1 1 3 5 5 6
3


Actual output:
3
-1 1 3 5 5 6


Fixed submission (verdict: Accepted):
n = int(input()) - 1
a = list(map(int, input().split()))

count = 0
flag  = 1

while flag:
    flag = 0
    for i in range( n, 0, -1 ):
        if a[i] < a[i-1]:
            t = a[i]
            a[i] = a[i-1]
            a[i-1] = t
            count += 1
            flag = 1

print(*a)
print(count)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)



Failing test case input:
6
2 1 -1 9 1 0

Expected output:
-1 0 1 1 2 9
9


Actual output:
9


Fixed submission (verdict: Accepted):
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(*a)
print(count)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):


import sys
import os
import math


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


def bubble_sort(A):
    swap_num = 0
    while True:
        swapped = False
        for i in range(N - 1):
            if A[i] > A[i + 1]:
                A[i], A[i + 1] = A[i + 1], A[i]
                swap_num += 1
                swapped = True
        if not swapped:
            return A, swap_num

A, num = bubble_sort(A)
print(num)
print(*A)

Failing test case input:
5
4 23 -3 2 -1

Expected output:
-3 -1 2 4 23
7


Actual output:
7
-3 -1 2 4 23


Fixed submission (verdict: Accepted):


import sys
import os
import math


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


def bubble_sort(A):
    swap_num = 0
    while True:
        swapped = False
        for i in range(N - 1):
            if A[i] > A[i + 1]:
                A[i], A[i + 1] = A[i + 1], A[i]
                swap_num += 1
                swapped = True
        if not swapped:
            return A, swap_num

A, num = bubble_sort(A)
print(*A)
print(num)
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)


Failing test case input:
6
1 1 0 2 -1 -1

Expected output:
-1 -1 0 1 1 2
10


Actual output:
1 1 0 2 -1 -1
1 1 0 2 -1 -1
0 1 1 2 -1 -1
0 1 1 2 -1 -1
-1 0 1 1 2 -1
-1 -1 0 1 1 2


Fixed submission (verdict: Accepted):
def bubbleSort(A,N):  
    flag = 1
    i = 0  
    while flag == 1:
        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
                i += 1
    print(*A)
    print(i)

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

bubbleSort(A,N)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
N = int(input())
A = [int(i) for i in input().split(" ")]
def bubble(A, N):
    count = 0
    flag = True
    while flag == True:
        flag = False
        for j in range(N-1, 0, -1):
            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)

Failing test case input:
6
2 1 -1 11 -1 0

Expected output:
-1 -1 0 1 2 11
9


Actual output:
-1 2 1 -1 11 0
3
-1 -1 2 1 0 11
6
-1 -1 0 2 1 11
8
-1 -1 0 1 2 11
9
-1 -1 0 1 2 11
9


Fixed submission (verdict: Accepted):
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]):
                A[i-1], A[i] = A[i], A[i-1]
                cnt += 1
                flag = True

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

bubble_sort(A, N)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)

Failing test case input:
5
0 47 -3 1 0

Expected output:
-3 0 0 1 47
5


Actual output:
0 47 -3 1 0
0 -3 0 1 47
4


Fixed submission (verdict: Accepted):
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)

bubble_sort(A, N)
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)

Failing test case input:
6
4 1 -1 3 0 0

Expected output:
-1 0 0 1 3 4
10


Actual output:
-1 0 0 1 3 4
13


Fixed submission (verdict: Accepted):
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 = 1
    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)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
N   = int(input())
A   = input().split()
cou = 0

for mak in range(1,N) :
    for j in range(mak,N)[ : : -1] :
        if A[j] < A[j - 1] :
            tem      = str(A[j])
            A[j]     = str(A[j - 1])
            A[j - 1] = str(tem)
            cou = cou + 1
print(' '.join(A))
print(cou)

Failing test case input:
5
0 26 -3 3 1

Expected output:
-3 0 1 3 26
5


Actual output:
-3 0 1 26 3
4


Fixed submission (verdict: Accepted):
N   = int(input())
A   = [int(temp) for temp in input().split()]
cou = 0

for mak in range(1,N) :
    for j in range(mak,N)[ : : -1] :
        if A[j] < A[j - 1] :
            tem      = int(A[j])
            A[j]     = int(A[j - 1])
            A[j - 1] = int(tem)
            cou = cou + 1
A   = [str(temp) for temp in A]
print(' '.join(A))
print(cou)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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))

Failing test case input:
5
1 19 -3 -1 2

Expected output:
-3 -1 1 2 19
5


Actual output:
None


Fixed submission (verdict: Accepted):
def bubbleSort(A, N):
    s = 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
                s += 1
    t = str(A[0])
    for i in range(1,N):
        t = t + " " + str(A[i])
    print(t)
    print(s)

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

bubbleSort(a, n)
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
def bubbleSort(A, N): 
    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]:
                
                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)


Failing test case input:
6
1 1 3 3 2 5

Expected output:
1 1 2 3 3 5
2


Actual output:
1 1 3 3 2 5
2


Fixed submission (verdict: Accepted):
def bubbleSort(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]:
                
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
    print(" ".join(map(str,A)))
    print(count)

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

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)




Failing test case input:
6
2 1 -1 11 1 0

Expected output:
-1 0 1 1 2 11
9


Actual output:
-1 0 1 1 2 11
8


Fixed submission (verdict: Accepted):
n = int(input())
nums = list(map(int, input().split()))
count = 0


while True:
    flag = 0

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

    if flag != 1:
        break

print(' '.join([str(i) for i in nums]))
print(count)
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
n = int(input())
A = [int(i) for i in input().split(' ')]

def trace(A):
    for index, v in enumerate(A):
        print(v, end='')
        if index != len(A) - 1:
            print(' ', end='')
    print()

def bubble_sort(A, n):
    i = n - 1
    counter = 0
    while i >= 1:
        j = i - 1
        while j >= 0:
            if A[i] < A[j]:
                A[i], A[j] = A[j], A[i]
                counter += 1
            j -= 1
        i -= 1
    trace(A)
    print(counter)

bubble_sort(A, n)

Failing test case input:
6
-1 1 5 3 3 2

Expected output:
-1 1 2 3 3 5
5


Actual output:
-1 1 2 3 3 5
4


Fixed submission (verdict: Accepted):
n = int(input())
A = [int(i) for i in input().split(' ')]



def trace(A):
    for index, v in enumerate(A):
        print(v, end='')
        if index != len(A) - 1:
            print(' ', end='')
    print()

def bubble_sort(A, n):
    i = 0
    counter = 0
    while i <= n - 1:
        j = n - 1
        while j >= i + 1:
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                counter += 1
            j -= 1
        i += 1
    trace(A)
    print(counter)

bubble_sort(A, n)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):

A = []



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)



Failing test case input:
5
0 13 -3 2 1

Expected output:
-3 0 1 2 13
5


Actual output:
-3 0 1 13 2
4


Fixed submission (verdict: Accepted):

A = []



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 int(A[M]) < int(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)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)
            

Failing test case input:
5
4 39 -2 2 1

Expected output:
-2 1 2 4 39
7


Actual output:
4 39 -2 2 1
0


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
count = 0
flag = True
while flag:
    flag = False
    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 = True
            count += 1
print(*A)
print(count)
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)



Failing test case input:
5
1 83 -3 1 1

Expected output:
-3 1 1 1 83
4


Actual output:

Fixed submission (verdict: Accepted):
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)

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


bubbleSort(A,N)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):


S = int(input())
N = list(map(int,input().split()))
count=0
def bubblesort(n,s):
    global count
    flag = 1
    while flag:
        flag = 0
        for i in range(s-1,0,-1):
            key = n[i]
            if n[i]<n[i-1]:
                n[i]=n[i-1]
                n[i-1]=key
                count+=1
                flag=1
        
bubblesort(N,S)
print(count)

Failing test case input:
5
4 4 5 3 0

Expected output:
0 3 4 4 5
7


Actual output:
7


Fixed submission (verdict: Accepted):


S = int(input())
N = list(map(int,input().split()))
count=0
def bubblesort(n,s):
    global count
    flag = 1
    while flag:
        flag = 0
        for i in range(s-1,0,-1):
            key = n[i]
            if n[i]<n[i-1]:
                n[i]=n[i-1]
                n[i-1]=key
                count+=1
                flag=1
    print(" ".join(list(map(str,n))))
    print(count)
        
bubblesort(N,S)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)

Failing test case input:
6
0 1 5 5 3 2

Expected output:
0 1 2 3 5 5
5


Actual output:
0 1 2 3 5 5
11


Fixed submission (verdict: Accepted):
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)
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)


Failing test case input:
5
0 23 -3 2 -1

Expected output:
-3 -1 0 2 23
6


Actual output:
0 23 -3 2 -1
0


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
flag = True
c = 0
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
            c += 1
print(*a)
print(c)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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);


Failing test case input:
5
1 19 -1 -1 2

Expected output:
-1 -1 1 2 19
5


Actual output:
1 19 -1 -1 2
-1 1 19 -1 2
-1 -1 1 19 2
-1 -1 1 2 19
-1 -1 1 2 19
-1 -1 1 2 19


Fixed submission (verdict: Accepted):
count = int(input());
data = [int(n) for n in input().split(" ")];

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

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

bubble_sort(data);

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)




Failing test case input:
6
0 1 -1 9 1 0

Expected output:
-1 0 0 1 1 9
6


Actual output:
-1 0 0 1 1 9
5


Fixed submission (verdict: Accepted):
n = int(input())
nums = list(map(int, input().split()))
count = 0


while True:
    flag = 0

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

    if flag != 1:
        break

print(' '.join([str(i) for i in nums]))
print(count)
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)



Failing test case input:
5
1 47 -3 1 1

Expected output:
-3 1 1 1 47
4


Actual output:
1 -3 1 1 47
3


Fixed submission (verdict: Accepted):
def bubble_sort(A):
    swap_cnt = 0
    for i in range(len(A)):
        for j in range(len(A) - 1, i, -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)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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]))



Failing test case input:
5
1 19 -3 -1 2

Expected output:
-3 -1 1 2 19
5


Actual output:
5
-3 -1 1 2 19


Fixed submission (verdict: Accepted):
n = int(input())
nums = list(map(int, input().split()))
count = 0


while True:
    flag = 0

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

    if flag != 1:
        break

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

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):

def bubbleSort(A,N):
    flag=1
    while flag:
        flag=0
        j=N-1
        while j>0:
            if(A[j]<A[j-1]):
                A[j],A[j-1]=A[j-1],A[j]
                flag=1
            j-=1

N=int(input())
A=[int(x) for x in input().split()]
bubbleSort(A,N)
print(A)

Failing test case input:
5
7 3 2 4 1

Expected output:
1 2 3 4 7
8


Actual output:
[1, 2, 3, 4, 7]


Fixed submission (verdict: Accepted):

def bubbleSort(A,N):
    c=0
    flag=1
    while flag:
        flag=0
        j=N-1
        while j>0:
            if(int(A[j])<int(A[j-1])):
                c+=1
                A[j],A[j-1]=A[j-1],A[j]
                flag=1
            j-=1
    return c

N=int(input())
A=input().split()
c=bubbleSort(A,N)
S=""
for i in range(N-1):
    S+=A[i]+" "
S+=str(A[-1])
print(S)
print(c)
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):

A = []



LENGTH =int(input())
A = input().split()


N = 0
M = LENGTH - 1
CHANGE = 0



while N <= LENGTH -1 :
    M = LENGTH - 1
    print ('N=',N)

    while M >= N + 1:
        print  ('-M=',M)

        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)


Failing test case input:
5
4 2 4 3 1

Expected output:
1 2 3 4 4
7


Actual output:
N= 0
-M= 4
-M= 3
-M= 2
-M= 1
N= 1
-M= 4
-M= 3
-M= 2
N= 2
-M= 4
-M= 3
N= 3
-M= 4
N= 4
1 2 3 4 4
7


Fixed submission (verdict: Accepted):

A = []



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 int(A[M]) < int(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)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)



Failing test case input:
6
0 1 0 5 3 2

Expected output:
0 0 1 2 3 5
4


Actual output:
[0, 0, 1, 2, 3, 5]
0


Fixed submission (verdict: Accepted):
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 != len(s) - 1:
        print(s[i], end=" ")
    else:
        print(s[i])

print(e)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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] 
    print(' '.join(map(str,a)))
    if sorted(a) == a: flag = False




Failing test case input:
5
1 91 -3 1 1

Expected output:
-3 1 1 1 91
4


Actual output:
-3 1 91 1 1
-3 1 1 91 1
-3 1 1 1 91


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))

flag = True
judge = True
count=0

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] 
            count+=1
    if sorted(a) == a: flag = False

print(' '.join(map(str,a)))
print(count)
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)




Failing test case input:
5
4 39 -2 2 0

Expected output:
-2 0 2 4 39
7


Actual output:
7


Fixed submission (verdict: Accepted):
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(*a)
print(count)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
def bubbleSort(A, N):
      ctn = 0
      for i in range(0,N):
            for j in range(0,N-i-1):
                  if A[j] > A[j+1]:
                        t = A[j]
                        A[j] = A[j+1]
                        A[j+1] = t
                        ctn = ctn + 1
      for i in range(0,N):
            if i < N-1:
                  print(A[i],end=' ')
            else:
                  print(A[i])
      print(ctn)

if __name__ == "__main__":
      N = int(input())
      A = (input()).split()
      bubbleSort(A, N)

Failing test case input:
5
4 39 -3 2 0

Expected output:
-3 0 2 4 39
7


Actual output:
-3 0 2 39 4
8


Fixed submission (verdict: Accepted):
def bubbleSort(A, N):
      ctn = 0
      for i in range(0,N):
            for j in range(0,N-i-1):
                  if int(A[j]) > int(A[j+1]):
                        t = A[j]
                        A[j] = A[j+1]
                        A[j+1] = t
                        ctn = ctn + 1
      for i in range(0,N):
            if i < N-1:
                  print(A[i],end=' ')
            else:
                  print(A[i])
      print(ctn)

if __name__ == "__main__":
      N = int(input())
      A = input()
      A = A.split()
      bubbleSort(A, N)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
n = int(input())
a = list(input().split())
count = 0
for i in range(n):
    for j in range(n):
        if a[j] < a[j-1]:
            a[j],a[j-1] = a[j-1],a[j]
            count += 1

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

Failing test case input:
6
1 1 3 6 3 5

Expected output:
1 1 3 3 5 6
2


Actual output:
1 3 5 3 1 6
35


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().strip().split()))
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
print(' '.join(map(str,a)))
print(count)
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)





Failing test case input:
6
1 1 0 2 0 -1

Expected output:
-1 0 0 1 1 2
10


Actual output:
-1 0 0 1 1 2
6


Fixed submission (verdict: Accepted):
n = int(input())
nums = list(map(int, input().split()))
count = 0


while True:
    flag = 0

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

    if flag != 1:
        break

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

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)


Failing test case input:
5
1 38 -1 -1 1

Expected output:
-1 -1 1 1 38
5


Actual output:
1 38 -1 -1 1
0


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
flag = True
c = 0
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
            c += 1
print(*a)
print(c)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)

Failing test case input:
6
8 1 3 6 1 3

Expected output:
1 1 3 3 6 8
8


Actual output:
8 1 3 6 1 3
1 1 3 3 6 8
8


Fixed submission (verdict: Accepted):
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)

bubble_sort(A, N)
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)



Failing test case input:
6
4 1 0 2 0 0

Expected output:
0 0 0 1 2 4
10


Actual output:
0 0 0 1 2 4


Fixed submission (verdict: Accepted):
def bubble(l):
	count = 0
	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
				count += 1

	return l, count


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

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

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

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):

A = []



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)


Failing test case input:
5
4 39 -2 2 1

Expected output:
-2 1 2 4 39
7


Actual output:
-2 1 2 39 4
8


Fixed submission (verdict: Accepted):

A = []



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 int(A[M]) < int(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)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
def main():
  element_num = int(input())
  elements = [int(s) for s in input().split()]
  swap_count = 0

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

  print(elements)
  print(swap_count)
  return 0

if __name__ == '__main__':
  main()

Failing test case input:
6
2 1 -1 9 1 0

Expected output:
-1 0 1 1 2 9
9


Actual output:
[-1, 0, 1, 1, 2, 9]
9


Fixed submission (verdict: Accepted):
def main():
  element_num = int(input())
  elements = [int(s) for s in input().split()]
  swap_count = 0

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

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

if __name__ == '__main__':
  main()
Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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)




Failing test case input:
6
4 1 -1 3 0 0

Expected output:
-1 0 0 1 3 4
10


Actual output:
-1 0 0 1 3 4 10


Fixed submission (verdict: Accepted):
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)-1:
            print(ls[i])
        else:
            print(ls[i],end=" ")
    print(ch)

Problem: p02259
Buggy submission (Python3, verdict: Wrong Answer):
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')


Failing test case input:
6
3 2 -1 4 0 0

Expected output:
-1 0 0 2 3 4
9


Actual output:
-1
0
0
2
3
4
9


Fixed submission (verdict: Accepted):
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])
print(count)