Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from itertools import count

def merge(A, left, mid, right, counter):
  n1, n2 = mid - left, right - mid
  L, R = [None]*(n1+1), [None]*(n2+1)
  for i in range(n1):
    L[i] = A[left + i]
  for i in range(n2):
    R[i] = A[mid + i]
  L[n1], R[n2] = float("inf"), float("inf")
  i, j = 0, 0
  for k in range(left, right):
    next(counter)
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1

def mergeSort(A, left, right, counter):
  if left+1 < right:
    mid = (left + right)//2;
    mergeSort(A, left, mid, counter)
    mergeSort(A, mid, right, counter)
    merge(A, left, mid, right, counter)

N = int(input())
A = [int(i) for i in input().split()]
counter = count(0)
mergeSort(A, 0, len(A), counter)
print(*A)
print(next(counter))

Fixed submission:
def merge(A, left, mid, right):
  global counter
  n1, n2 = mid - left, right - mid
  L, R = list(A[left:left+n1]+[float("inf")]), list(A[mid:mid+n2]+[float("inf")])
  i = j = 0
  for k in range(left, right):
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
  counter += right - left
def mergeSort(A, left, right):
  if left+1 < right:
    mid = (left + right)//2;
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)

N = int(input())
A = [int(i) for i in input().split()]
counter = 0
mergeSort(A, 0, len(A))
print(*A)
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from itertools import count

def merge(A, left, mid, right, counter):
  n1, n2 = mid - left, right - mid
  L, R = [None]*(n1+1), [None]*(n2+1)
  for i in range(n1):
    L[i] = int(A[left + i])
  for i in range(n2):
    R[i] = int(A[mid + i])
  L[n1], R[n2] = float("inf"), float("inf")
  i, j = 0, 0
  for k in range(left, right):
    next(counter)
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1

def mergeSort(A, left, right, counter):
  if left+1 < right:
    mid = (left + right)//2;
    mergeSort(A, left, mid, counter)
    mergeSort(A, mid, right, counter)
    merge(A, left, mid, right, counter)

N = int(input())
A = input().split()
counter = count(0)
mergeSort(A, 0, len(A), counter)
print(*A)
print(next(counter))

Fixed submission:
def merge(A, left, mid, right):
  global counter
  n1, n2 = mid - left, right - mid
  L, R = list(A[left:left+n1]+[float("inf")]), list(A[mid:mid+n2]+[float("inf")])
  i = j = 0
  for k in range(left, right):
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
  counter += right - left
def mergeSort(A, left, right):
  if left+1 < right:
    mid = (left + right)//2;
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)

N = int(input())
A = [int(i) for i in input().split()]
counter = 0
mergeSort(A, 0, len(A))
print(*A)
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from itertools import count

def merge(A, left, mid, right, counter):
  n1, n2 = mid - left, right - mid
  L, R = [None]*(n1+1), [None]*(n2+1)
  for i in range(n1):
    L[i] = A[left + i]
  for i in range(n2):
    R[i] = A[mid + i]
  L[n1] = R[n2] = float("inf")
  i = j = 0
  for k in range(left, right):
    next(counter)
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1

def mergeSort(A, left, right, counter):
  if left+1 < right:
    mid = (left + right)//2;
    mergeSort(A, left, mid, counter)
    mergeSort(A, mid, right, counter)
    merge(A, left, mid, right, counter)

N = int(input())
A = [int(i) for i in input().split()]
counter = count(0)
mergeSort(A, 0, len(A), counter)
print(*A)
print(next(counter))

Fixed submission:
def merge(A, left, mid, right):
  global counter
  n1, n2 = mid - left, right - mid
  L, R = list(A[left:left+n1]+[float("inf")]), list(A[mid:mid+n2]+[float("inf")])
  i = j = 0
  for k in range(left, right):
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
  counter += right - left
def mergeSort(A, left, right):
  if left+1 < right:
    mid = (left + right)//2;
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)

N = int(input())
A = [int(i) for i in input().split()]
counter = 0
mergeSort(A, 0, len(A))
print(*A)
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from itertools import count

def merge(A, left, mid, right):
  global counter
  n1, n2 = mid - left, right - mid
  L, R = [None]*(n1+1), [None]*(n2+1)
  for i in range(n1):
    L[i] = A[left + i]
  for i in range(n2):
    R[i] = A[mid + i]
  L[n1] = R[n2] = float("inf")
  i = j = 0
  for k in range(left, right):
    counter += 1
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1

def mergeSort(A, left, right):
  if left+1 < right:
    mid = (left + right)//2;
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)

N = int(input())
A = [int(i) for i in input().split()]
counter = 0
mergeSort(A, 0, len(A))
print(*A)
print(counter)

Fixed submission:
def merge(A, left, mid, right):
  global counter
  n1, n2 = mid - left, right - mid
  L, R = list(A[left:left+n1]+[float("inf")]), list(A[mid:mid+n2]+[float("inf")])
  i = j = 0
  for k in range(left, right):
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
  counter += right - left
def mergeSort(A, left, right):
  if left+1 < right:
    mid = (left + right)//2;
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)

N = int(input())
A = [int(i) for i in input().split()]
counter = 0
mergeSort(A, 0, len(A))
print(*A)
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from itertools import count

def merge(A, left, mid, right):
  global counter
  n1, n2 = mid - left, right - mid
  L, R = [None]*(n1+1), [None]*(n2+1)
  for i in range(n1):
    L[i] = A[left + i]
  for i in range(n2):
    R[i] = A[mid + i]
  L[n1] = R[n2] = float("inf")
  i = j = 0
  for k in range(left, right):
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1
  counter += right - left
def mergeSort(A, left, right):
  if left+1 < right:
    mid = (left + right)//2;
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)

N = int(input())
A = [int(i) for i in input().split()]
counter = 0
mergeSort(A, 0, len(A))
print(*A)
print(counter)

Fixed submission:
def merge(A, left, mid, right):
  global counter
  n1, n2 = mid - left, right - mid
  L, R = list(A[left:left+n1]+[float("inf")]), list(A[mid:mid+n2]+[float("inf")])
  i = j = 0
  for k in range(left, right):
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
  counter += right - left
def mergeSort(A, left, right):
  if left+1 < right:
    mid = (left + right)//2;
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)

N = int(input())
A = [int(i) for i in input().split()]
counter = 0
mergeSort(A, 0, len(A))
print(*A)
print(counter)