Buggy python submission (verdict: Runtime Error):
h,w  = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
res = []
for _ in range(h):
    res.append("")
line = 0

def insert(res,i,l):
    if l %2 == 0:
        res[l] = res[l] + str(i+1)
    else:
        res[l] = str(i+1) + res[l]

for i in range(0,n):
    ammount=a[i]
    while len(res[line]) < w and ammount > 0:
        insert(res,i,line)
        ammount -= 1
    if len(res[line]) == w:
        line += 1
    while ammount >= w:
        res[line] = str(i+1) * w
        ammount -= w
        line += 1
    if ammount > 0:
        res[line] = str(i+1) * ammount

res_se = []
for st in res:
    res_se.append(list(st))

for i in range(0,h):
    print(' '.join(res_se[i]))

Fixed submission:
h,w  = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
res = []
for _ in range(h):
    res.append([])
line = 0

def insert(res,i,l):
    if l %2 == 0:
        res[l].append(str(i+1))
    else:
        res[l].insert(0,str(i+1))

for i in range(0,n):
    ammount=a[i]
    while len(res[line]) < w and ammount > 0:
        insert(res,i,line)
        ammount -= 1
    if len(res[line]) == w:
        line += 1
    while ammount >= w:
        res[line] = [str(i+1) for _ in range(w)]
        ammount -= w
        line += 1
    if ammount > 0:
        res[line] = [str(i+1) for _ in range(ammount)]

for i in range(0,h):
    print(' '.join(res[i]))

Buggy python submission (verdict: Runtime Error):
h,w  = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
res = []
for _ in range(h):
    res.append("")
line = 0

def insert(res,i,l):
    if l %2 == 0:
        res[l] = res[l] + str(i+1)
    else:
        res[l] = str(i+1) + res[l]

for i in range(0,n):
    ammount=a[i]
    while len(res[line]) < w and ammount > 0:
        insert(res,i,line)
        ammount -= 1
    if len(res[line]) == w:
        line += 1
    while ammount >= w:
        res[line] = str(i+1) * w
        ammount -= w
        line += 1
    if ammount > 0:
        res[line] = str(i+1) * ammount

length = len(res)
for i in range(length):
    print(res[i])

Fixed submission:
h,w  = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
res = []
for _ in range(h):
    res.append([])
line = 0

def insert(res,i,l):
    if l %2 == 0:
        res[l].append(str(i+1))
    else:
        res[l].insert(0,str(i+1))

for i in range(0,n):
    ammount=a[i]
    while len(res[line]) < w and ammount > 0:
        insert(res,i,line)
        ammount -= 1
    if len(res[line]) == w:
        line += 1
    while ammount >= w:
        res[line] = [str(i+1) for _ in range(w)]
        ammount -= w
        line += 1
    if ammount > 0:
        res[line] = [str(i+1) for _ in range(ammount)]

for i in range(0,h):
    print(' '.join(res[i]))

Buggy python submission (verdict: Runtime Error):
h,w  = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
res = []
for _ in range(h):
    res.append("")
line = 0

def insert(res,i,l):
    if l %2 == 0:
        res[l] = res[l] + str(i+1)
    else:
        res[l] = str(i+1) + res[l]

for i in range(0,n):
    ammount=a[i]
    while len(res[line]) < w and ammount > 0:
        insert(res,i,line)
        ammount -= 1
    if len(res[line]) == w:
        line += 1
    while ammount >= w:
        res[line] = str(i+1) * w
        ammount -= w
        line += 1
    if ammount > 0:
        res[line] = str(i+1) * ammount

print('\n'.join(map(str, res)))

Fixed submission:
h,w  = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
res = []
for _ in range(h):
    res.append([])
line = 0

def insert(res,i,l):
    if l %2 == 0:
        res[l].append(str(i+1))
    else:
        res[l].insert(0,str(i+1))

for i in range(0,n):
    ammount=a[i]
    while len(res[line]) < w and ammount > 0:
        insert(res,i,line)
        ammount -= 1
    if len(res[line]) == w:
        line += 1
    while ammount >= w:
        res[line] = [str(i+1) for _ in range(w)]
        ammount -= w
        line += 1
    if ammount > 0:
        res[line] = [str(i+1) for _ in range(ammount)]

for i in range(0,h):
    print(' '.join(res[i]))