Buggy python submission (verdict: Runtime Error):
from collections import deque

def out(time, parking):
  x = len(parking)
  outs1 = []
  outs2 = []
  for i in range(x):
    for j in range(2):
      if parking[i][j] != None:
        parking[i][j][0] -= time
  
  for i in range(x):
    c1 = parking[i][0]
    c2 = parking[i][1]
    if c1 != None and c2 != None:
      if c1[0] <= 0 and c2[0] <= 0:
        outs1.append(c2[1])
        outs2.append(c1[1])
        parking[i][0] = None
        parking[i][1] = None
      elif c2[0] <= 0:
        outs1.append(c2[1])
        parking[i][1] = None
    elif c1 != None:
      if c1[0] <= 0:
        outs1.append(c1[1])
        parking[i][0] = None
    elif c2 != None:
      if c2[0] <= 0:
        outs.append(c2[1])
        parking[i][1] = None
  outs1.sort()
  outs2.sort()
  return outs1 + outs2

def into(num, time, parking):
  x = len(parking)
  times = []
  for i in range(x):
    if parking[i] == [None, None]:
      parking[i][0] = [time, num]
      return
    if parking[i][0] == None:
      times.append((parking[i][1][0], i))
    elif parking[i][1] == None:
      times.append((parking[i][0][0], i))
  times.sort()
  
  for t, ind in times:
    if t >= time:
      if parking[ind][0] == None:
        parking[ind][0] = [time, num]
      else:
        parking[ind][1] = [time, num]
      break
  else:
    max_t = t

  for t, ind in times:
    if t == max_t:
      if parking[ind][0] == None:
        parking[ind][0] = [time, num]
      else:
        parking[ind][1] = [time, num]
      break
 
while True:
  m, n = map(int, input().split())
  if m == 0:
    break
  
  parking = [[None] * 2 for _ in range(m)]
  wait = deque()
  space = m * 2
  ans = []
  
  for t in range(120 * n):
    o = out(1, parking)
    if o:
      space += len(o)
      ans += o

    if t % 10 == 0 and t <= 10 * (n - 1):
      time = int(input())
      wait.append((t // 10 + 1, time))

    for i in range(min(space, len(wait))):
      num, time = wait.popleft()
      into(num, time, parking)
      space -= 1
  print(*ans)


Fixed submission:
from collections import deque

def out(time, parking):
  x = len(parking)
  outs = []
  for i in range(x):
    for j in range(2):
      if parking[i][j] != None:
        parking[i][j][0] -= time
  
  for i in range(x):
    c1 = parking[i][0]
    c2 = parking[i][1]
    if c1 != None and c2 != None:
      if c1[0] <= 0 and c2[0] <= 0:
        outs.append([c2[1], c1[1]])
        parking[i][0] = None
        parking[i][1] = None
      elif c2[0] <= 0:
        outs.append([c2[1]])
        parking[i][1] = None
    elif c1 != None:
      if c1[0] <= 0:
        outs.append([c1[1]])
        parking[i][0] = None
    elif c2 != None:
      if c2[0] <= 0:
        outs.append([c2[1]])
        parking[i][1] = None
  lst = []
  for l in outs:
    lst += l
  return lst

def into(num, time, parking):
  x = len(parking)
  times = []
  for i in range(x):
    if parking[i] == [None, None]:
      parking[i][0] = [time, num]
      return
    if parking[i][0] == None:
      times.append((parking[i][1][0], i))
    elif parking[i][1] == None:
      times.append((parking[i][0][0], i))
  times.sort()
  
  for t, ind in times:
    if t >= time:
      if parking[ind][0] == None:
        parking[ind][0] = [time, num]
      else:
        parking[ind][1] = [time, num]
      return
  else:
    max_t = t

  for t, ind in times:
    if t == max_t:
      if parking[ind][0] == None:
        parking[ind][0] = [time, num]
      else:
        parking[ind][1] = [time, num]
      return
 
while True:
  m, n = map(int, input().split())
  if m == 0:
    break
  
  parking = [[None] * 2 for _ in range(m)]
  wait = deque()
  space = m * 2
  ans = []
  
  for t in range(120 * n):
    o = out(1, parking)
    if o:
      space += len(o)
      ans += o

    if t % 10 == 0 and t <= 10 * (n - 1):
      time = int(input())
      wait.append((t // 10 + 1, time))

    for i in range(min(space, len(wait))):
      num, time = wait.popleft()
      into(num, time, parking)
      space -= 1
  print(*ans)