CodeEff/ECCO huggingface dataset:
# Original solution
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
#import numpy as np
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())

A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

#割引券を使う場合
ans = sys.maxsize
for _ in range(M) :
  x, y, c = list(map(int, input().split()))
  ans = min(ans, a[x-1]+b[y-1]-c)

#その他の組み合わせ
for i in range(A) :
  for j in range(B) :
    ans = min(ans, a[i] + b[j])

print (ans)



# Optimized solution
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
#import numpy as np
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())

A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

#割引券を使う場合
ans = sys.maxsize
for _ in range(M) :
  x, y, c = list(map(int, input().split()))
  ans = min(ans, a[x-1]+b[y-1]-c)

#その他の組み合わせ
ans = min(ans, min(a)+min(b))

print (ans)
# Original solution
a,b,m=list(map(int,input().split()))
ai=list(map(int, input().split()))
bi=list(map(int, input().split()))
sm=[list(map(int, input().split())) for _ in range(m)]
ans=10**6
for i in range(a):
    for j in range(b):
        for x in range(m):
            k=ai[i]+bi[j]
            if sm[x][0]==i+1 and sm[x][1]==j+1:
                k=k-sm[x][2]
            if ans >=k:
                ans=k
print(ans)


# Optimized solution
a,b,m=list(map(int,input().split()))
ai=list(map(int, input().split()))
bi=list(map(int, input().split()))
sm=[list(map(int, input().split())) for _ in range(m)]
k=min(ai)+min(bi)

for x in range(m):
    
    l=ai[sm[x][0]-1]+bi[sm[x][1]-1]-sm[x][2]
    k=min(k,l)

print(k)
# Original solution
s = list(map(int, input().split(" ")))

a = s[0]
b = s[1]
m = s[2]

a_l = list(map(int, input().split(" ")))
b_l = list(map(int, input().split(" ")))

ans = a_l[0] + b_l[0]

for i in range(m):
    x = list(map(int, input().split(" ")))
    if ans > (a_l[x[0] - 1] + b_l[x[1] -1] - x[2]):
        ans = a_l[x[0] -1] + b_l[x[1] -1] - x[2]
        
while len(a_l) > 0:
    a_ = a_l.pop(0)
    for v in b_l:
        if ans > (a_ + v):
            ans = a_ + v

print(ans)

# Optimized solution
s = list(map(int, input().split(" ")))

a = s[0]
b = s[1]
m = s[2]

a_l = list(map(int, input().split(" ")))
b_l = list(map(int, input().split(" ")))

ans = min(a_l) + min(b_l)

for i in range(m):
    x = list(map(int, input().split(" ")))
    if ans > (a_l[x[0] - 1] + b_l[x[1] -1] - x[2]):
        ans = a_l[x[0] -1] + b_l[x[1] -1] - x[2]


print(ans)
# Original solution
A, B, M = list(map(int, input().split()))
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
m = []
for n in range(M):
    m.append([int(s) for s in input().split()])

min = a[0] + b[0]
for i in range( len(a)):
    for j in range(len(b)):
        price = a[i] + b[j]
        discountPrice = price
        for k in range(M):
            if i + 1 in m[k] and j + 1 in m[k]:
                discountPrice = price - m[k][2]
            if min > discountPrice:
                min = discountPrice


print(min)


# Optimized solution
A, B, M = list(map(int, input().split()))
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
m = []


for n in range(M):
    m.append([int(s) for s in input().split()])

minValue = min(a) + min(b)

for i in range(M):
    discountPrice = a[m[i][0] - 1] + b[m[i][1] - 1] - m[i][2]
    if discountPrice  < minValue:
        minValue = discountPrice

print(minValue)
# Original solution
A,B,M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m=[]
for i in range(M):
    array = list(map(int, input().strip().split()))
    m.append(array)

def hitachi02(a,b,m):
    results=[]
    for i in range(len(a)):
        for j in range(len(b)):
            for k in range(len(m)):
                if i+1 == m[k][0] and j+1 == m[k][1]:
                    cal = a[i]+b[j]-m[k][2]
                else:
                    cal = a[i]+b[j]
                results.append(cal)
    result=min(results)
    return result

result=hitachi02(a,b,m)
print(result)

# Optimized solution
A,B,M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m=[]
for i in range(M):
    array = list(map(int, input().strip().split()))
    m.append(array)

def hitachi02(a,b,m):
    results=[]
    cal01=min(a)+min(b)
    for k in range(len(m)):
        results.append(a[m[k][0]-1]+b[m[k][1]-1]-m[k][2])
    cal02=min(results)
    if cal01>=cal02:
        return cal02
    else:
        return cal01

result=hitachi02(a,b,m)
print(result)
# Original solution
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
tickets = {}
for _ in range(M):
    x, y, c = list(map(int, input().split()))
    if (x, y) in tickets:
        if tickets[(x, y)] < c:
            tickets[(x, y)] = c
    else:
        tickets[(x, y)] = c

min_price = float("inf")
for i, price_a in enumerate(a, 1):
    for j, price_b in enumerate(b, 1):
        total_price = price_a + price_b
        if (i, j) in tickets:
            total_price -= tickets[(i, j)]
        if min_price > total_price:
            min_price = total_price

print(min_price)

# Optimized solution
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

min_price = min(a) + min(b)
for _ in range(M):
    x, y, c = list(map(int, input().split()))
    discount_price = a[x-1] + b[y-1] - c
    if min_price > discount_price:
        min_price = discount_price
        
print(min_price)
# Original solution
a, b, m = list(map(int,input().split()))
dr = list(map(int,input().split()))
wa = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for i in range(m)]
low = 200001

for i in range(m):
    f = xyc[i][0] - 1
    d = xyc[i][1] - 1
    if low >= dr[f]+wa[d]-xyc[i][2]:
        low = dr[f]+wa[d]-xyc[i][2]

dr.sort()
wa.sort()

if low >= (dr[0] + wa[0]):
    print((dr[0] + wa[0]))
else:
    print(low)

# Optimized solution
a, b, m = list(map(int,input().split()))
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
low = min(al)+min(bl)
x = [0] * m
y = [0] * m
c = [0] * m

for i in range(m):
    x[i],y[i],c[i] = list(map(int, input().split()))
    x[i] -= 1
    y[i] -= 1
 
for i in range(m):
    low = min(low,al[x[i]]+bl[y[i]]-c[i])

print(low)
# Original solution
A, B, M = list(map(int, input().split()))
a = list(input().split())
b = list(input().split())
l = []
n = []
for i in range(M):
  x, y, c = list(map(int, input().split()))
  l.append(int(a[x-1])+int(b[y-1])-c)
for k in range(A):
  for m in range(B):
    n.append(int(a[k])+int(b[m]))
print((min(min(l), min(n))))

# Optimized solution
A, B, M = list(map(int, input().split()))
a = list(input().split())
b = list(input().split())
l = []
for i in range(M):
  x, y, c = list(map(int, input().split()))
  l.append(int(a[x-1])+int(b[y-1])-c)
l.sort()
n = int(min(a)) + int(min(b))
print((min(l[0], n)))
# Original solution
A, B, M = list(map(int,input().split()))
val_m = [[0] * 3 for i in range(M)]

val_a = list(map(int, input().split()))
val_b = list(map(int, input().split()))

for i in range(M):
  val_m[i][0], val_m[i][1], val_m[i][2] = list(map(int, input().split()))

dis_val = []
for i in range(M):
  dis_val.append(val_a[val_m[i][0]-1] + val_b[val_m[i][1]-1] - val_m[i][2])


val_a = list(set(val_a))
val_b = list(set(val_b))
sum_val = []
for i in range(len(val_a)):
  for j in range(len(val_b)):
    sum_val.append(val_a[i] + val_b[j])


sum_val.extend(dis_val)
sum_val.sort()
print((sum_val[0]))

# Optimized solution
A, B, M = list(map(int,input().split()))
val_m = [[0] * 3 for i in range(M)]

val_a = list(map(int, input().split()))
val_b = list(map(int, input().split()))

for i in range(M):
  val_m[i][0], val_m[i][1], val_m[i][2] = list(map(int, input().split()))

dis_val = []
for i in range(M):
  dis_val.append(val_a[val_m[i][0]-1] + val_b[val_m[i][1]-1] - val_m[i][2])

val_a = list(set(val_a))
val_b = list(set(val_b))

val_a.sort()
val_b.sort()
dis_val.sort()

sum_val = val_a[0] + val_b[0]
if(sum_val <= dis_val[0]):
  print(sum_val)
else:
  print((dis_val[0]))
# Original solution
import itertools

a,b,m = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
P = [list(map(int,input().split())) for i in range(m)]
x = []
y = []
#普通に足算する
p = itertools.product(A, B)
for v in p:
    x.append(sum(v))
#min出す
xx = min(x)    
#割引券使う
for i in range(m):
  y.append(A[P[i][0]-1] + B[P[i][1]-1] - P[i][2])
#min出す
yy = min(y)
print((min(xx,yy)))



# Optimized solution
import itertools

a,b,m = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
P = [list(map(int,input().split())) for i in range(m)]
y = []
#普通に足算する
aa = min(A)
bb = min(B)
xx =aa+bb

#割引券使う
for i in range(m):
  y.append(A[P[i][0]-1] + B[P[i][1]-1] - P[i][2])
#min出す
yy = min(y)

print((min(xx,yy)))
# Original solution
import sys

def disscount(disscounts,x,y):
  minDisscounts = 0
  for i in disscounts:
    if int(i[0]) == x and int(i[1]) == y:
      if minDisscounts < int(i[2]):
        minDisscounts = int(i[2])
  return minDisscounts

counts = input().split()
colors = input().split()
hots = input().split()
disscounts = []
for i in range(int(counts[2])):
  disscounts.append(input().split())

minPrice = sys.maxsize
for i in range(0, len(colors)):
  for j in range(0, len(hots)):
    colorPrice = int(colors[i])
    hotPrice = int(hots[j])
    price = colorPrice + hotPrice - disscount(disscounts, i + 1 , j + 1)
    if price < minPrice:
      minPrice = price
print((str(minPrice)))

# Optimized solution
import sys

counts = list(map(int,input().split()))
colors = list(map(int,input().split()))
hots = list(map(int,input().split()))

ticketCount = counts[2]

minPrice = sys.maxsize
# first. get disscount consider price
for i in range(ticketCount):
  values = input().split()
  x = int(values[0])
  y = int(values[1])
  dissPrice = int(values[2])
  colorPrice = colors[x-1]
  hotsPrice = hots[y-1]
  validPrice =  colorPrice + hotsPrice - dissPrice
  if minPrice > validPrice:
    minPrice = validPrice

max_color = min(colors)
max_color_idx = colors.index(max_color)
max_hots = min(hots)
max_hots_idx = hots.index(max_hots)
validPrice = max_color + max_hots
if minPrice > validPrice:
  minPrice = validPrice
print((str(minPrice)))
# Original solution
A, B, M = [int(i) for i in input().split(" ")]

a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]
C = []

for i in range(M):
  c = [int(i) for i in input().split(" ")]
  C.append(c)

m = 1000000

for i in a:
  for j in b:
    cost = i + j
    if m >= cost:
      m = cost

for c in C:
  cost = a[c[0] - 1] + b[c[1] - 1] - c[2]
  if m >= cost:
    m = cost

print(m)

# Optimized solution
A, B, M = [int(i) for i in input().split(" ")]

a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]
C = []

for i in range(M):
  c = [int(i) for i in input().split(" ")]
  C.append(c)

m = min(a) + min(b)

for c in C:
  cost = a[c[0] - 1] + b[c[1] - 1] - c[2]
  if m >= cost:
    m = cost

print(m)
# Original solution
A,B,M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
z = []
x = []
y = []
c = []
for i in range(M):
    z.append(list(map(int, input().split())))
    x.append(z[i][0])
    y.append(z[i][1])
    c.append(z[i][2])

mi = min(a) + min(b)

for i in range(M):
    if a[x[i]-1] + b[y[i]-1] - c[i] < mi:
        mi = a[x[i]-1] + b[y[i]-1] - c[i]

print(mi)

# Optimized solution
a,b,m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
for i in range(m):
    x.append(list(map(int, input().split())))

min_a = min(a)
min_b = min(b)
money = min_a + min_b

for i in range(m):
    kingaku = a[x[i][0]-1] + b[x[i][1]-1] - x[i][2]
    if kingaku < money:
        money = kingaku

print(money)
# Original solution
a, b, m = list(map(int, input().split()))
ref = list(map(int, input().split()))
micro = list(map(int, input().split()))
tk = [list(map(int, input().split())) for i in range(m)]

mini = 10 ** 6
for i in range(a):
    for j in range(b):
        s = ref[i] + micro[j]
        if s < mini:
            mini = s

amount = 10 ** 6
for i in tk:
    if ref[i[0]-1] + micro[i[1]-1] - i[2] < amount:
        amount = ref[i[0]-1] + micro[i[1]-1] - i[2]

print((min(mini, amount)))


# Optimized solution
a, b, m = list(map(int, input().split()))
ref = list(map(int, input().split()))
micro = list(map(int, input().split()))
tk = [list(map(int, input().split())) for i in range(m)]

mini = min(ref) + min(micro)

amount = 10 ** 6
for i in tk:
    if ref[i[0]-1] + micro[i[1]-1] - i[2] < amount:
        amount = ref[i[0]-1] + micro[i[1]-1] - i[2]

print((min(mini, amount)))
# Original solution
As, Bs, Ms = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

mm = [[0 for i in range(Bs)] for j in range(As)]
for i in range(Ms):
  a, b, c = list(map(int, input().split()))
  if c > mm[a-1][b-1]:
    mm[a-1][b-1] = c

ans = 1000000
for i,a in enumerate(A):
  for j,b in enumerate(B):
    if ans > a+b-mm[i][j]:
      ans = a+b-mm[i][j]
print(ans)

# Optimized solution
As, Bs, Ms = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

bas = min(A) + min(B)

ans = bas
for i in range(Ms):
  a, b, c = list(map(int, input().split()))
  if A[a-1]+B[b-1]-c < ans:
    ans = A[a-1]+B[b-1]-c

print(ans)
# Original solution
import itertools

A, B, M = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

x = [0] * M
y = [0] * M
c = [0] * M

ans = []

for i in range(M):
    x[i], y[i], c[i] = [int(k) for k in input().split()]

temp = list(itertools.product(a, b))
for i,j in temp:
    ans.append(i+j)


for i in range(M):
    ans.append(a[x[i]-1] + b[y[i]-1] - c[i])

print((min(ans)))

# Optimized solution
import itertools

A, B, M = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

x = [0] * M
y = [0] * M
c = [0] * M

ans = []

for i in range(M):
    x[i], y[i], c[i] = [int(k) for k in input().split()]

for i in range(M):
    ans.append(a[x[i]-1] + b[y[i]-1] - c[i])

a = set(a)
b = set(b)
temp = list(itertools.product(a, b))
for i,j in temp:
    ans.append(i+j)

print((min(ans)))
# Original solution
import itertools

A, B, M = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

x = [0] * M
y = [0] * M
c = [0] * M

ans = []

for i in range(M):
    x[i], y[i], c[i] = [int(k) for k in input().split()]
    ans.append(a[x[i] - 1] + b[y[i] - 1] - c[i])

a = set(a)
b = set(b)
temp = list(itertools.product(a, b))
for i,j in temp:
    ans.append(i+j)

print((min(ans)))

# Optimized solution
A, B, M = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

x = [0] * M
y = [0] * M
c = [0] * M

ans = []
ans.append(min(a) + min(b))
for i in range(M):
    x[i], y[i], c[i] = [int(k) for k in input().split()]

for i in range(M):
    ans.append(a[x[i] - 1] + b[y[i] - 1] - c[i])

print((min(ans)))
# Original solution
a,b,m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int,input().split())) for _ in range(m)]


yes_m = a[xyc[0][0]-1]+b[xyc[0][1]-1] - xyc[0][2]

for i in range(1,m):
    if yes_m > a[xyc[i][0]-1]+b[xyc[i][1]-1] - xyc[i][2]:
        yes_m = a[xyc[i][0]-1]+b[xyc[i][1]-1] - xyc[i][2]

no_m = min(a)+min(b)

print((min(no_m,yes_m)))


# Optimized solution
a,b,m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a)+min(b)

for i in range(m):
    x,y,c = list(map(int, input().split()))
    ans = min(ans, a[x-1]+b[y-1]-c)
print(ans)
# Original solution
import itertools


A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = {}
for _ in range(M):
    x, y, z = list(map(int, input().split()))
    key = str(x) + "&" + str(y)
    if key in list(m.keys()):
        if m[key] < z:
            m[key] = z
    else:
        m[key] = z
A_B = list(itertools.product(list(range(1, A + 1)), list(range(1, B + 1))))
A_B_sum = list([x[0] + x[1] for x in (itertools.product(a, b))])
for i in range(len(A_B)):
    # print(str(A_B[i][0]) + "&" + str(A_B[i][1]))
    if str(A_B[i][0]) + "&" + str(A_B[i][1]) in list(m.keys()):
        # print(str(A_B[i][0]) + "&" + str(A_B[i][1]))
        A_B_sum[i] -= m[str(A_B[i][0]) + "&" + str(A_B[i][1])]
print((min(A_B_sum)))

# Optimized solution
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min_a = min(a)
min_b = min(b)
ans = min_a + min_b
for _ in range(M):
    i, j, c = list(map(int, input().split()))
    ans = min(ans, a[i - 1] + b[j - 1] - c)
print(ans)
# Original solution
A,B,M=list(map(int, input().split()))
As=list(map(int, input().split()))
Bs=list(map(int, input().split()))
List=[]
for i in range(M):
  List.append(list(map(int, input().split())))
ans=10000000000
for i in As:
  for j in Bs:
    ans=min(ans, i+j)
for l in List:
  candidate=As[l[0]-1]+Bs[l[1]-1]-l[2]
  ans = min(ans, candidate)
print(ans)

# Optimized solution
A,B,M=list(map(int, input().split()))
As=list(map(int, input().split()))
Bs=list(map(int, input().split()))
List=[]
for i in range(M):
  List.append(list(map(int, input().split())))

ans=min(As)+min(Bs)
for l in List:
  candidate=As[l[0]-1]+Bs[l[1]-1]-l[2]
  ans = min(ans, candidate)
print(ans)
# Original solution
A, B, M = list(map(int, input().split()))
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

m = []

for i in range(M):
    x, y, z = list(map(int, input().split()))
    m.append([x, y, z])
m.sort(reverse = True, key=lambda x: x[2])

for j in m[:min(len(a),len(b)+1)]:
    if a[j[0]-1] + b[j[1]-1] - j[2] >= 0 and a[j[0]-1] + b[j[1]-1] - j[2] < min(a) + min(b):
        print((a[j[0]-1] + b[j[1]-1] - j[2]))
        exit()

print((min(a) + min(b)))

# Optimized solution
A, B, M = list(map(int, input().split()))
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

m = []
am = min(a)
bm = min(b)

for i in range(M):
    x, y, z = list(map(int, input().split()))

    m.append(a[x-1] + b[y-1] - z )



if am + bm > min(m):
    print((min(m)))
else:
    print((am + bm))
# Original solution
A, B, M = list(map(int, input().split()))
# items
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# discount
d = [list(map(int,input().split())) for i in range(M)]

list = []

for i in range(M):
  if min(a) + min(b) > a[d[i][0] - 1] + b[d[i][1] - 1] - d[i][2]:
    list.append(a[d[i][0] - 1] + b[d[i][1] - 1] - d[i][2])

if len(list) != 0:
  print((min(list)))
else:
  print((min(a) + min(b)))

# Optimized solution
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min = min(a) + min(b)

for i in range(M):
  x, y, c = list(map(int, input().split()))
  tmp = a[x - 1] + b[y - 1] - c
  if min > tmp:
    min = tmp

print(min)
# Original solution
# input
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y, c = [0] * M, [0] * M, [0] * M
for i in range(M):
    x[i], y[i], c[i] = list(map(int, input().split()))
ans = float("inf")

for i in range(M):
    ans = min(ans, a[x[i]-1] + b[y[i]-1] - c[i])

for i in range(A):
    for j in range(B):
        ans = min(ans, a[i] + b[j])
print(ans)


# Optimized solution
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a) + min(b)
for i in range(M):
    x, y, c = list(map(int, input().split()))
    ans = min(ans, a[x-1] + b[y-1] - c)
print(ans)
# Original solution
A,B,M = list(map(int,input().split()))
A_li = list(map(int,input().split()))
B_li = list(map(int,input().split()))
X = set()
Y = set()
inf = float("inf")
posibility = inf

for m in range(M):
    x,y,c=list(map(int,input().split()))
    tmp_posibility=A_li[x-1]+B_li[y-1]-c
    posibility=min(posibility,tmp_posibility)
    X.add(x)
    Y.add(y)

import itertools 
a_li = set(A_li)-X
b_li = set(B_li)-Y

for a,b in itertools.product(a_li,b_li):
    tmp_posibility = a+b
    posibility = min(posibility,tmp_posibility)



print(posibility)

# Optimized solution
A,B,M = list(map(int,input().split()))
A_li = list(map(int,input().split()))
B_li = list(map(int,input().split()))

inf = float("inf")
posibility = inf

for m in range(M):
    x,y,c=list(map(int,input().split()))
    tmp_posibility=A_li[x-1]+B_li[y-1]-c
    posibility=min(posibility,tmp_posibility)
 

no_c = min(A_li)+min(B_li)
decition = min(posibility,no_c)

print(decition)
# Original solution
A,B,M = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = float("inf")
for i in range(M):
  x,y,c = list(map(int,input().split()))
  ans = min(a[x-1]+b[y-1]-c,ans)
  
for i in range(A):
  for j in range(B):
    ans = min(ans,a[i]+b[j])
    
print(ans)
    

# Optimized solution
A,B,M = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = float("inf")
for i in range(M):
  x,y,c = list(map(int,input().split()))
  ans = min(a[x-1]+b[y-1]-c,ans)
  
ans = min(ans,min(a)+min(b))
    
print(ans)
# Original solution
a, b, m = list(map(int, input().split()))
ax = list(map(int, input().split()))
bx = list(map(int, input().split()))
x = []
for i in range(m):
    _x = list(map(int, input().split()))
    x.append(list(_x))

min_sum = 99999999
for i in range(a):
    for j in range(b):
        sum = ax[i] + bx[j]
        for k in x:
            sum2 = sum
            if k[0] == i+1 and k[1] == j+1:
                sum2 = sum2 - k[2]
            if sum2 < min_sum:
                min_sum = sum2

print(("{}".format(min_sum)))

# Optimized solution
a, b, m = list(map(int, input().split()))
ax = list(map(int, input().split()))
bx = list(map(int, input().split()))
x = []
for i in range(m):
    _x = list(map(int, input().split()))
    x.append(list(_x))

min_a = min(ax)
min_b = min(bx)
min_sum = min_a + min_b

for k in x:
    sum = ax[k[0]-1] + bx[k[1]-1] - k[2]
    if sum < min_sum:
        min_sum = sum

print(("{}".format(min_sum)))
# Original solution
A,B,M = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
oldp = 10**20
c = [[0 for _ in range(B)] for _ in range(A)]
for _ in range(M):
    x, y, cp = list(map(int,input().split()))
    p = a[x-1]+b[y-1]-cp
    if oldp > p:
        oldp = p

p = min(a)+min(b)
print((min(oldp,p)))

# Optimized solution
A,B,M = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))

oldp = min(a)+min(b)

for _ in range(M):
    x, y, cp = list(map(int,input().split()))
    p = a[x-1]+b[y-1]-cp
    if oldp > p:
        oldp = p

print(oldp)
# Original solution
a, b, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = min(a)
bb = min(b)
aabb = aa+bb
ab = [a+b for a, b in zip(a, b)]
ans = []
for i in ab:
    ans.append(i)

for i in range(m):
    x, y, c = list(map(int, input().split()))
    ans.append(a[x-1]+b[y-1]-c)

ans.append(aabb)
print((min(ans)))

# Optimized solution
a, b, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = min(a)
bb = min(b)
aabb = aa+bb
ans = []
ans.append(aabb)
for i in range(m):
    x, y, c = list(map(int, input().split()))
    ans.append(a[x-1]+b[y-1]-c)
print((min(ans)))