Buggy python submission (verdict: Time Limit Exceeded):
S = [int(e) for e in input().split()]
list_a =  [int(e) for e in input().split()]
list_b =  [int(e) for e in input().split()]

dis_list = []

for i in range(S[2]):
    dis_list.append([int(e) for e in input().split()])

cost_list = []
min_num = min(list_a) + min(list_b)

for i in list_a:
    for j in list_b:
        cost_list.append(i+j)


for l in dis_list:
    if (cost_list[S[0]*(l[0]-1)+l[1]-1] - l[2]) < min_num:
        min_num = cost_list[S[0]*(l[0]-1)+l[1]-1] - l[2]

print(min_num)

Fixed submission:
S = [int(e) for e in input().split()]
list_a =  [int(e) for e in input().split()]
list_b =  [int(e) for e in input().split()]

dis_list = []

for i in range(S[2]):
    dis_list.append([int(e) for e in input().split()])

min_num1 = min(list_a) + min(list_b)

min_num2_list = []

for l in dis_list:
    min_num2_list.append(list_a[l[0]-1] + list_b[l[1]-1] - l[2])

min_num2 = min(min_num2_list)

if min_num1 > min_num2:
    print(min_num2)
else:
    print(min_num1)

Buggy python submission (verdict: Time Limit Exceeded):
S = [int(e) for e in input().split()]
list_a =  [int(e) for e in input().split()]
list_b =  [int(e) for e in input().split()]

dis_list = []

for i in range(S[2]):
    dis_list.append([int(e) for e in input().split()])

cost_list = []

for i in list_a:
    for j in list_b:
        cost_list.append(i+j)


for l in dis_list:
    cost_list.append(cost_list[S[0]*(l[0]-1)+l[1]-1] - l[2])

min_num = cost_list[0]

for i in cost_list:
    if i < min_num:
        min_num = i

print(min_num)


Fixed submission:
S = [int(e) for e in input().split()]
list_a =  [int(e) for e in input().split()]
list_b =  [int(e) for e in input().split()]

dis_list = []

for i in range(S[2]):
    dis_list.append([int(e) for e in input().split()])

min_num1 = min(list_a) + min(list_b)

min_num2_list = []

for l in dis_list:
    min_num2_list.append(list_a[l[0]-1] + list_b[l[1]-1] - l[2])

min_num2 = min(min_num2_list)

if min_num1 > min_num2:
    print(min_num2)
else:
    print(min_num1)

Buggy python submission (verdict: Time Limit Exceeded):
S = [int(e) for e in input().split()]
# S = list(map(int, input().replace(' ', '')))
list_a =  [int(e) for e in input().split()]
# list_a = list(map(int, input().replace(' ', '')))
list_b =  [int(e) for e in input().split()]
# list_b = list(map(int, input().replace(' ', '')))

dis_list = []

for i in range(S[2]):
    dis_list.append([int(e) for e in input().split()])

cost_list = []

for i in list_a:
    for j in list_b:
        cost_list.append(i+j)

for l in dis_list:
    cost_list.append(cost_list[S[0]*(l[0]-1)+l[1]-1] - l[2])

print(min(cost_list))
# print('cost_list:',cost_list)
# print('list_a:',list_a)
# print('list_b:',list_b)

Fixed submission:
S = [int(e) for e in input().split()]
list_a =  [int(e) for e in input().split()]
list_b =  [int(e) for e in input().split()]

dis_list = []

for i in range(S[2]):
    dis_list.append([int(e) for e in input().split()])

min_num1 = min(list_a) + min(list_b)

min_num2_list = []

for l in dis_list:
    min_num2_list.append(list_a[l[0]-1] + list_b[l[1]-1] - l[2])

min_num2 = min(min_num2_list)

if min_num1 > min_num2:
    print(min_num2)
else:
    print(min_num1)