Buggy python submission (verdict: Runtime Error):
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)
 
N = int(input())
A = input()
BS(A, N)


Fixed submission:
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)
 
N = int(input())
A = input()
BS(A, N)

Buggy python submission (verdict: Runtime Error):
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)
 
N = int(input())
A = input()
BS(A, N)


Fixed submission:
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)
 
N = int(input())
A = input()
BS(A, N)

Buggy python submission (verdict: Runtime Error):
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(" ".join(map(str,A)))
    print(count)

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


Fixed submission:
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)
 
N = int(input())
A = input()
BS(A, N)

Buggy python submission (verdict: Runtime Error):
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(" ".join(map(str,A)))
    print(count)

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


Fixed submission:
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)
 
N = int(input())
A = input()
BS(A, N)

Buggy python submission (verdict: Runtime Error):
N = int(input()) #要素数
A = list(map(int,input().split())) #ソート対象（スペース区切り→配列に展開）
 
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(' '.join(map(str,A)))
print(cnt)


Fixed submission:
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)
 
N = int(input())
A = input()
BS(A, N)

Buggy python submission (verdict: Runtime Error):
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(" ".join(map(str,A)))
    print(count)
 
N = int(input())
A = input()
bubbleSort(A, N)


Fixed submission:
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)
 
N = int(input())
A = input()
BS(A, N)