CodeEff/ECCO huggingface dataset:
# Original solution
A, B, M = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

xyc_list = []
for i in range(M):
    xyc_list.append(list(map(int, input().split())))

total_min = min(a_list) + min(b_list)
for x,y,c in xyc_list:
    if a_list[x-1] in a_list and b_list[y-1] in b_list:
        total = a_list[x-1] + b_list[y-1] - c
        if total_min > total:
            total_min = total

print(total_min)


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

xyc_list = []
for i in range(M):
    xyc_list.append(list(map(int, input().split())))

total_min = min(a_list) + min(b_list)
for x,y,c in xyc_list:
    total = a_list[x-1] + b_list[y-1] - c
    if total_min > total:
        total_min = total

print(total_min)
# Original solution


a,b,m = [int(x) for x in input().split()]
an = [(int(x),i+1) for i,x in enumerate(input().split())]
bn = [(int(x),i+1) for i,x in enumerate(input().split())]

an = sorted(an)
bn = sorted(bn)

discounts = {}
discount_list = []
for i in range(m):
    x,y,c = [int(x) for x in input().split()]
    if (x,y) in discounts and discounts[(x,y)] > c:
        continue
    discounts[(x,y)] = c
    discount_list.append(c)

discount_list = sorted(discount_list,reverse=True)

i = 0
j = 0
min = an[0][0]+bn[0][0]
max_discount = max(discount_list)
len_an = len(an)
len_bn = len(bn)

# print(an)
# print(bn)
# print(min)
# print(discounts)

for ai in an:
    for bj in bn:
        a_index = ai[1]
        b_index = bj[1]
        discount = 0
        if (a_index, b_index) in discounts:
            discount = discounts[(a_index, b_index)]
        total = ai[0] + bj[0] - discount
        if min > total:
            min = total

        if ai[0] + bj[0] - max_discount > min:
            break



# while True:
#     a_index = an[i][1]
#     b_index = bn[j][1]
#     discount = 0
#     if (a_index, b_index) in discounts:
#         discount = discounts[(a_index, b_index)]
#     total = an[i][0] + bn[j][0] - discount
#     if min > total:
#         min = total
#
#     if an[i][0] + bn[j][0] - max_discount > min:
#         break
#     elif i == len_an-1 and j == len_bn-1:
#         break
#     elif i == len_an-1:
#         j += 1
#     elif j == len_bn-1:
#         i += 1
#     else:
#         a_diff = an[i+1][0] - an[i][0]
#         b_diff = bn[j+1][0] - an[j][0]
#         if a_diff < b_diff:
#             i += 1
#         else:
#             j += 1

print(min)





# Optimized solution


a,b,m = [int(x) for x in input().split()]
an = [int(x) for x in input().split()]
bn = [int(x) for x in input().split()]

ans = min(an)+min(bn)
for i in range(m):
    p, q, discount = [int(x) for x in input().split()]
    a_cost = an[p-1]
    b_cost = bn[q-1]
    total = a_cost + b_cost - discount
    ans = min(total, ans)

print(ans)
# Original solution
import itertools

a, b, m = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
m_list = [list(map(int, input().split())) for _ in range(m)]
kumiawase_kingaku = float('inf')
for ab in itertools.product(a_list, b_list):
    if ab[0] + ab[1] < kumiawase_kingaku:
        kumiawase_kingaku = ab[0] + ab[1]

for x, y, c in m_list:
    reizouko = a_list[x-1]
    denshirenji = b_list[y-1]
    kingaku = reizouko + denshirenji - c
    if kingaku < kumiawase_kingaku:
        kumiawase_kingaku = kingaku

print(kumiawase_kingaku)


# Optimized solution
import itertools

a, b, m = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
m_list = [list(map(int, input().split())) for _ in range(m)]

kumiawase_kingaku = min(a_list) + min(b_list)

for x, y, c in m_list:
    reizouko = a_list[x-1]
    denshirenji = b_list[y-1]
    kingaku = reizouko + denshirenji - c
    if kingaku < kumiawase_kingaku:
        kumiawase_kingaku = kingaku

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

ans = 10000000000

for i in range(A):
    for j in range(B):
        for k in range(m):
            if(i+1 == x[k] and j+1 == y[k]):
                price = a[i] + b[j] - c[k]
            else:
                price = a[i] + b[j]
            ans = min(ans,price)
print(ans)

# Optimized solution
A,B,m = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = [0 for _ in range(m)]
y = [0 for _ in range(m)]
c = [0 for _ in range(m)]
for i in range(m):
    x[i],y[i],c[i] = list(map(int,input().split()))

ans = min(a)+min(b)

for i in range(m):
    ans = min(ans,(a[x[i]-1] + b[y[i]-1]) - c[i])
print(ans)
# Original solution
#読み込み
list_num = input().split(" ") #A,B,M
list_ref = input().split(" ") #冷蔵庫の値段
list_ren = input().split(" ") #レンジの値段
list2 = [] #割引できるやつの組み
for i in range(int(list_num[2])):
    list_c = input().split(" ")
    list2.append(list_c)
A = int(list_num[0])
B = int(list_num[1])
M = int(list_num[2])

#割引なしで総当たり
list_price = []
for i in range(A):
    for j in range(B):
        list_price.append(int(list_ref[i]) + int(list_ren[j]))

#割引きを総当たり
for k in range(M):
    price = int(list_ref[int(list2[k][0])-1]) + int(list_ren[int(list2[k][1])-1]) - int(int(list2[k][2])-1) - 1
    list_price.append(price)


print((min(list_price)))

# Optimized solution
#読み込み
list_num = input().split(" ") #A,B,M
list_ref = input().split(" ") #冷蔵庫の値段
list_ren = input().split(" ") #レンジの値段
list2 = [] #割引できるやつの組み
for i in range(int(list_num[2])):
    list_c = input().split(" ")
    list2.append(list_c)
A = int(list_num[0])
B = int(list_num[1])
M = int(list_num[2])

list_price = []

#一番安いのと一番安いの
list_ref_int = [int(s) for s in list_ref]
list_ren_int = [int(s) for s in list_ren]
cheap = min(list_ref_int) + min(list_ren_int)
list_price.append(cheap)

#割引きを総当たり
for k in range(M):
    price = list_ref_int[int(list2[k][0])-1] + list_ren_int[int(list2[k][1])-1] - int(int(list2[k][2])-1) - 1
    list_price.append(price)

print((min(list_price)))
# Original solution
a, b ,c = list(map(int,input().split(" ")))
ap =[]
ap = list(map(int,input().split(" ")))
bp =[]
bp = list(map(int,input().split(" ")))
lowest = 10000000
for i in ap:
    for j in bp:
        lowest = min(lowest,i+j)
for _ in range(c):
    x, y ,z = list(map(int,input().split(" ")))
    dis = ap[x-1] + bp[y-1] - z
    lowest = min(lowest,dis)
print(lowest)

# Optimized solution
a, b ,c = list(map(int,input().split(" ")))
ap =[]
ap = list(map(int,input().split(" ")))
bp =[]
bp = list(map(int,input().split(" ")))
lowest = 10000000
ma = min(ap)
mb = min(bp)
lowest = ma +mb
for _ in range(c):
    x, y ,z = list(map(int,input().split(" ")))
    dis = ap[x-1] + bp[y-1] - z
    lowest = min(lowest,dis)
print(lowest)
# Original solution
a,b,m=list(map(int, input().split()))
fridge=list(map(int, input().split()))
microwave=list(map(int, input().split()))
s=[list(map(int,list(input().split()))) for i in range(m)]
discount = [[0 for i in range(b)] for j in range(a)]


def mapDiscountByXY(m,discount,s):
  for i in range(m):
    if discount[s[i][0]-1][s[i][1]-1] < s[i][2]:
      discount[s[i][0]-1][s[i][1]-1] = s[i][2]
  return discount


def findMin(a,b,fridge,microwave,discount):
  lowest = 100000
  
  for i in range(a):
    for j in range(b):
      if lowest > fridge[i]+microwave[j]-discount[i][j]:
        lowest = fridge[i]+microwave[j]-discount[i][j]
  return lowest


discount = mapDiscountByXY(m,discount,s)
print((findMin(a,b,fridge,microwave,discount)))

# Optimized solution
_,a,b,*t = [list(map(int,i.split())) for i in open(0)]
n=min(a)+min(b)
for x,y,c in t:
  n=min(n,a[x-1]+b[y-1]-c)
print(n)
# Original solution
na,nb,nm = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
TA = []
for i in range(nm):
    m1, m2, m3 = list(map(int,input().split()))
    T = a[m1-1]+b[m2-1]-m3
    TA.append(T)
for i in range(na):
    for j in range(nb):
        T = a[i] + b[j]
        TA.append(T)
print((min(TA)))

# Optimized solution
na,nb,nm = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
TA = []
for i in range(nm):
    m1, m2, m3 = list(map(int,input().split()))
    T = a[m1-1]+b[m2-1]-m3
    TA.append(T)
T = min(a) + min(b)
TA.append(T)
print((min(TA)))
# Original solution
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = list(list(map(int, input().split())) for _ in range(M))
l1 = []
lx = []
ly = []
min_a = min(a)
min_b = min(b)

for k in range(M):
    lx.append(list(x for x, y, c in xyc))
    ly.append(list(y for x, y, c in xyc))
    l1.append(list(c for x, y, c in xyc))
    j = lx[0][k]
    p = ly[0][k]
    max_l1 = max(list(map(int, max(l1))))
    ans = min((min_a + min_b), ((a[j - 1] + b[p - 1]) - max_l1))
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 k 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 = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for k in range(M):
    x, y, c = list(map(int, input().split()))
    ans = min(ans, ((a[x - 1] + b[y - 1]) - c))
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 k 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()))
Ai = list(map(int,input().split()))
Bi = list(map(int,input().split()))
amin = min(Ai)
bmin= min(Bi)
min = amin+bmin
for i in range(M):
	xi,yi,ci = list(map(int,input().split()))
	if Ai[xi-1] + Bi[yi-1] - ci < min:
		min = Ai[xi-1] + Bi[yi-1] - ci
print(min)


# Optimized solution
# hitachi2020_b.py
_, _, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = []
Y = []
C = []
amin = min(A)
bmin = min(B)
for i in range(M):
    x, y, c = list(map(int, input().split()))
    X.append(x)
    Y.append(y)
    C.append(c)

ans = amin+bmin
for i in range(M):
    if ans >= A[X[i]-1]+B[Y[i]-1]-C[i]:
        ans = A[X[i]-1]+B[Y[i]-1]-C[i]
print(ans)
# Original solution
# hitachi2020_b.py
_, _, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = []
Y = []
C = []
amin = min(A)
bmin = min(B)
for i in range(M):
    x, y, c = list(map(int, input().split()))
    X.append(x)
    Y.append(y)
    C.append(c)

ans = amin+bmin
for i in range(M):
    if ans >= A[X[i]-1]+B[Y[i]-1]-C[i]:
        ans = A[X[i]-1]+B[Y[i]-1]-C[i]
print(ans)


# Optimized solution
A,B,M = list(map(int,input().split()))
Ai = list(map(int,input().split()))
Bi = list(map(int,input().split()))
amin = min(Ai)
bmin= min(Bi)
min = amin+bmin
for i in range(M):
	xi,yi,ci = list(map(int,input().split()))
	if Ai[xi-1] + Bi[yi-1] - ci < min:
		min = Ai[xi-1] + Bi[yi-1] - ci
print(min)
# Original solution
[A, B, M] = [int(i) for i in input().split()]
a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]
min_amount = 2*10**5
for a in range(A):
  for b in range(B):
    amount = a_list[a] + b_list[b]
    min_amount = min(amount, min_amount)
for m in range(M):
  [x, y, c] = [int(i) for i in input().split()]
  amount = a_list[x-1] + b_list[y-1] - c
  min_amount = min(amount, min_amount)
print(min_amount)

# Optimized solution
[A, B, M] = [int(i) for i in input().split()]
a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]
min_amount = min(a_list) + min(b_list)

for m in range(M):
  [x, y, c] = [int(i) for i in input().split()]
  amount = a_list[x-1] + b_list[y-1] - c
  min_amount = min(amount, min_amount)
print(min_amount)
# Original solution
A,B,M=list(map(int,input().split()))

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

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()))
min=a[0]+b[0]
min1=0
for i in range(A):
    for j in range(B):
        for t in range(M):
            if i+1==x[t] and j+1==y[t]:
                min1=a[i]+b[j]-c[t]
            else:
                min1=a[i]+b[j]
            if min >= min1:
                min = min1
print(min)


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

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

price=[0]*(M+1)

price[0] = min(a)+min(b)

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

print((min(price)))
# Original solution
A, B, M = list(map(int, input().rstrip().split()))
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))

cost_sale=[]
for _ in range(M):
    x, y, c = list(map(int, input().rstrip().split()))
    tot = a[x-1] + b[y-1] - c
    cost_sale.append(tot)
    
cost_raw = [i + j for i in a for j in b]
print((min(cost_sale + cost_raw)))

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

cost=[]
for _ in range(M):
    x, y, c = list(map(int, input().rstrip().split()))
    tot = a[x-1] + b[y-1] - c
    cost.append(tot)
    
cost.append(min(a)+min(b))
print((min(cost)))
# Original solution
A, B, M = list(map(int,input().split()))

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

x = list()
y = list()
c = list()
for i in range(M):
    xi, yi, ci = list(map(int,input().split()))
    x.append(xi)
    y.append(yi)
    c.append(ci)

p = list()

for i in range(A):
    for j in range(B):
        pij = a[i] + b[j]
        p.append(pij)
        
for i in range(M):
    pi = a[x[i]-1] + b[y[i]-1] - c[i]
    p.append(pi)

print((min(p)))


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

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

x = list()
y = list()
c = list()
for i in range(M):
    xi, yi, ci = list(map(int,input().split()))
    x.append(xi)
    y.append(yi)
    c.append(ci)

p = list()

amin = min(a)
bmin = min(b)
pab  = amin + bmin
p.append(pab)
        
for i in range(M):
    pi = a[x[i]-1] + b[y[i]-1] - c[i]
    p.append(pi)

print((min(p)))
# 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()]
data = [list(map(int, input().split())) for _ in range(M)]

MIN = a[0] + b[0]

for i in range(A):
    for j in range(B):
        
        for k in data:
            if k[0]-1 == i and k[1]-1 == j:
                MIN = min(a[i]+b[j]-k[2], MIN)

        MIN = min(a[i]+b[j], MIN) 

print(MIN)

# 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()]
data = [list(map(int, input().split())) for _ in range(M)]

aMIN = min(a)
bMIN = min(b)

MIN = aMIN + bMIN

for k in data:
    MIN = min(MIN, a[k[0]-1]+b[k[1]-1]-k[2])


print(MIN)
# Original solution
#!/usr/bin/python
# coding: UTF-8

def main():
    A,B,M = list(map(int, input().split(' ')))

    a_list = list(map(int, input().split(' ')))
    b_list = list(map(int, input().split(' ')))

    dic = {}
    for i in range(A):
        dic[i]={}
    for i in range(A):
        for j in range(B):
            dic[i][j] = 0


    price_list = 2*10**5
    for i in range(M):
        temp = list(map(int, input().split(' ')))
        if price_list > a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]:
            price_list = a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]

    lower = min(a_list) + min(b_list)
    if lower < price_list:
        print(lower)
    else:
        print(price_list)

if __name__=='__main__':
    main()


# Optimized solution
#!/usr/bin/python
# coding: UTF-8

def main():
    A,B,M = list(map(int, input().split(' ')))

    a_list = list(map(int, input().split(' ')))
    b_list = list(map(int, input().split(' ')))


    price_list = 2*10**5
    for i in range(M):
        temp = list(map(int, input().split(' ')))
        if price_list > a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]:
            price_list = a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]

    lower = min(a_list) + min(b_list)
    if lower < price_list:
        print(lower)
    else:
        print(price_list)

if __name__=='__main__':
    main()
# Original solution
A,B,M = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
p = [i+j for i in a for j in b]
for _ in range(M):
    x,y,c = list(map(int,input().split()))
    p.append(a[x-1]+b[y-1]-c)

print((min(p)))

# Optimized solution
A,B,M = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
p = [min(a) + min(b)]
for _ in range(M):
    x,y,c = list(map(int,input().split()))
    p.append(a[x-1]+b[y-1]-c)

print((min(p)))
# 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()]
xyc = [[int(i) for i in input().split()] for _ in range(m)]
ans = 100000000
for x, y, c in xyc:
    ans = min(a[x-1] + b[y-1] - c, ans)
ans = min(min(a) + min(b), ans)
print(ans)

# Optimized solution
_, _, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mi = 10**6
for _ in range(m):
    x, y, c = list(map(int, input().split()))
    mi = min(mi, a[x-1] + b[y-1] - c)
print((min(mi, min(a)+min(b))))
# Original solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sys import stdin

def calc_ab_price_without_pricedown(a_list, b_list):
    ab_price = [[a_list[j]+b_list[i] for i in range(len(b_list))] for j in range(len(a_list))]

    return ab_price


def calc_pricedown(ab_price, pricedown_list):
    """値段表から値引きする"""
    for i, j, price in pricedown_list:
        for k, l, price2 in pricedown_list:
            if (i, j) == (k, l) and price >= price2:
                continue
            elif (i, j) == (k, l) and price < price2:
                price = 0

        ab_price[i-1][j-1] -= price

    return ab_price

def generate_table(a_list, b_list,  pricedown_list):
    min_a = min(a_list)
    min_b = min(b_list)
    min_price = min_a + min_b

    for i, j, price in pricedown_list:
        min_price = min(min_price, a_list[i-1]+b_list[j-1]-price)

    return min_price


def calc_min_price(a_list, b_list, ab_price):
    min_price = float('inf')
    for i in range(len(a_list)):
        for j in range(len(b_list)):
            min_price = min(ab_price[i][j], min_price)
    return min_price

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

a_list = [int(x) for x in stdin.readline().rstrip().split()]
b_list = [int(x) for x in stdin.readline().rstrip().split()]

pricedown_list = []
for i in range(m):
    pricedown_list.append([int(x) for x in stdin.readline().rstrip().split()])
    # pricedown_list.append((list(map(int, input().split()))))


# 割引せずに購入する場合の合計金額のうち、最低金額を算出
# ab_price = calc_ab_price_without_pricedown(a_list, b_list)

# 最低金額を算出
# min_price = calc_min_price(a_list, b_list, ab_price)

# 割引の値段を含めて考える
# pricedowned_ab = calc_pricedown( ab_price, pricedown_list)

min_price = generate_table(a_list, b_list,  pricedown_list)

# 値引き後の最低金額を算出
# min_price = calc_min_price(a_list, b_list, price_table)

print(min_price)




# Optimized solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sys import stdin


def calc_min_price(a_list, b_list,  pricedown_list):
    # 割引しない場合の最安組み合わせを算出する
    min_a = min(a_list)
    min_b = min(b_list)
    min_price = min_a + min_b

    # 割引したものも含めて一番安い値段を算出する
    for i, j, price in pricedown_list:
        min_price = min(min_price, a_list[i-1]+b_list[j-1]-price)

    return min_price


# 入力
a, b, m = list(map(int, input().split()))

# 商品値段リスト
a_list = [int(x) for x in stdin.readline().rstrip().split()]
b_list = [int(x) for x in stdin.readline().rstrip().split()]

# 値引きリスト
pricedown_list = []
for i in range(m):
    pricedown_list.append([int(x) for x in stdin.readline().rstrip().split()])

# 最小金額を計算する
min_price = calc_min_price(a_list, b_list,  pricedown_list)

# 出力
print(min_price)
# Original solution
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
z = [list(map(int, input().split())) for _ in range(M)]
mem = []

for i in range(len(a)):
    for j in range(len(b)):
        mem.append(a[i] + b[j])

for x, y, c in z:
    mem.append(a[x - 1] + b[y - 1] - c)

print((min(mem)))


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

reg = min(a) + min(b)
for x, y, c in L:
    tmp = a[x-1] + b[y-1] - c
    reg = min(reg, tmp)
print(reg)
# Original solution
A, B, M = list(map(int, input().split()))
lenzi=list(map(int,input().split()))
zouko=list(map(int,input().split()))
mPrice = 200000
for i in range(A):
  for j in range(B):
    if lenzi[i]+zouko[j]<mPrice:
      mPrice=lenzi[i]+zouko[j]
for i in range(M):
  x, y, c = list(map(int, input().split()))
  if lenzi[x-1]+zouko[y-1]-c<mPrice:
    mPrice=lenzi[x-1]+zouko[y-1]-c
print(mPrice)

# Optimized solution
A, B, M = list(map(int, input().split()))
lenzi=list(map(int,input().split()))
zouko=list(map(int,input().split()))
mlenzi=100000
mzouko=100000
mPrice = 200000
for i in range(A):
  if lenzi[i]<mlenzi:
    for j in range(B):
      if zouko[j]<mzouko:
        if lenzi[i]+zouko[j]<mPrice:
          mPrice=lenzi[i]+zouko[j]
        mzouko=zouko[j]
    mlenzi=lenzi[i]
for i in range(M):
  x, y, c = list(map(int, input().split()))
  if lenzi[x-1]+zouko[y-1]-c<mPrice:
    mPrice=lenzi[x-1]+zouko[y-1]-c
print(mPrice)
# Original solution
a,b,m = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = min(a)+min(b)
for i in range(m):
  x,y,c = list(map(int,input().split()))
  if count > a[x-1]+b[y-1]-c:
    count = a[x-1]+b[y-1]-c
    
print(count)

# Optimized solution
a,b,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=10**6
for i in range(m):
  x,y,c=list(map(int,input().split()))
  ans=min(ans,a[x-1]+b[y-1]-c)
print((min(ans,min(a)+min(b))))
# Original solution
A , B , M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [i+j for i in a for j in b]
for i in range(M):
    q = list(map(int, input().split()))
    x = a[q[0]-1] + b[q[1]-1] - q[2]
    ans.append(x)
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()))
ans = [min(a) + min(b)]
for i in range(M):
    q = list(map(int, input().split()))
    x = a[q[0]-1] + b[q[1]-1] - q[2]
    ans.append(x)
print((min(ans)))
# Original solution
na, nb, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min_a = min_b = 10**9
for i in range(na):
    min_a = min(min_a, a[i])
for i in range(nb):
    min_b = min(min_b, b[i])
ans = min_a + min_b
for i in range(m):
    x, y, c = list(map(int, input().split()))
    x -= 1
    y -= 1
    ans = min(ans, a[x] + b[y] - c)
print(ans)


# Optimized solution
from sys import stdin
input = lambda: stdin.readline().rstrip()
na, nb, 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()))
    x -= 1
    y -= 1
    ans = min(ans, a[x] + b[y] - c)
print(ans)