peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    s=[input() for i in range(N)]
    M=int(input())
    t=[input() for i in range(N)]
    ans=0
    for a in set(s):
        ans=max(ans,s.count(a)-t.count(a))
    print(ans)

if __name__ == '__main__':
    main()
# Judge status: Accepted
x,y=list(map(int,input().split()))
import sys
for i in range(0,x+1):
  if 2*i+4*(x-i)==y:
    print("Yes")
    sys.exit()
print("No")
# Judge status: Wrong Answer
N = int(input())
A = [int(a) for a in input().split()]
mod = 10**9+7
SUM = 0

maxA = max(A)
d = 0
while 1:
    if maxA < 2**d:
        break
    d += 1

BitA = [[0]*d for _ in range(N)]
for i in range(N):
    for j in range(d):
        BitA[i][j] = int(bin(A[i]|2**d)[3+j])

BitSumB = 0
for i in range(d):
    tmp = sum([BitA[j][i] for j in range(N)])
    BitSumB += 2 ** (d-i-1) * (tmp * (N - tmp))

print(BitSumB)
# Judge status: Accepted
import math
a, b, x = map(int, input().split())
if a*a*b==x:
    print(0)
elif a*a*b<=2*x:
    print(90-math.degrees(math.atan(a**3/(2*b*a*a-2*x))))
else:
    print(90-math.degrees(math.atan(2*x/(a*b*b))))
# Judge status: Accepted
n,a,b = map(int,input().split())
ans = 0
for i in range(n+1):
 if a <= sum(list(map(int,list(str(i))))) <= b:
  ans += i
print(ans)
# Judge status: Accepted
N = int(input())
D = [list(map(int,input().split())) for x in range(N)]
flag = ""

for p in range(N):
    if D[p][0] == D[p][1]:
        flag += "1"
    else:
        flag += "0"

if "111" in flag:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
x,y = map(int, input().split())
i = 'Yes' if x * 2 <= y <= x * 4 and y % 2 == 0 else 'No'
print(i)
# Judge status: Wrong Answer
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = 10 ** 8
for i in range(n-k+1):
    if x[i] <= 0:
        if x[i+k-1] > 0: 
            a = min(abs(x[i]), abs(x[i+k-1])) * 2 + max(abs(x[i]), abs(x[i+k-1]))
        else: 
            a = abs(x[i])
    else:
        a = abs(x[i+k-1])
    if ans > a: ans = a
print(ans)
# Judge status: Accepted
N = int(input())
*H, = map(int, input().split())
ans = 0

l, r = 0, 1
while l < N:
    v = H[l]
    a = 0
    while r < N:
        if H[r]<=v:
            a += 1
            v = H[r]
            r += 1
        else:
            l = r-1
            r = l+2
            break
    ans = max(ans, a)
    l+=1
print(ans)
# Judge status: Accepted
S = input()
T = input()
count = 0
for i in range(len(S)):
  if S[i] != T[i]:
    count += 1
print(count)
# Judge status: Accepted
import itertools
n,m,q = map(int, input().split())
a,b,c,d = [0]*q,[0]*q,[0]*q,[0]*q

for i in range(q):
    a[i],b[i],c[i],d[i] = map(int, input().split())

ans = 0

for C in itertools.combinations_with_replacement(range(1,m+1),n):
    x = 0
    for i in range(q):
        if C[b[i]-1] - C[a[i]-1] == c[i]:
            x += d[i]

    ans = max(ans,x)

print(ans)
# Judge status: Accepted
import bisect
n,k = map(int,input().split())
l = list(map(int,input().split()))


ans = 10**10

for i in range(n-k+1):
    count = 0
    left = l[i]
    right = l[i+k-1]
    if left <= 0 and right > 0:
        count = min(abs(left),abs(right))*2+max(abs(left),abs(right))
    elif right <= 0:
        count = abs(left)
    else:
        count = right
    ans = min(ans,count)
print(ans)
# Judge status: Accepted
N = int(input())
X = list(map(int, input().split()))

candidates = [sum(X) // N, sum(X) // N + 1]

ans = 0

a = 0
b = 0
for x in X:
    a += (x - candidates[0]) ** 2
    b += (x - candidates[1]) ** 2

if a < b:
    print(a)
else:
    print(b)
# Judge status: Wrong Answer
n, m= map(int, input().split())
got=0
sell={}
buy=0
for i in range(n):
  a,b=map(int,input().split())
  if a not in sell:
    sell[a]=0
  sell[a]+=b
if n==1:
  print(m*a)
  exit()
sell=sorted(sell.items())
for lis in sell:
  got+=lis[1]
  if got>m:
    buy+=(m-got+lis[1])*lis[0]
    print(buy)
    exit()
  else:
    buy+=(lis[0])*(lis[1])
# Judge status: Accepted
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

data = []
for i in range(1, N+1):
    data.append(i)

list_data = []
for val in itertools.permutations(data):
    list_data.append(val)

list_data.sort()

a = 0
b = 0
i = 1
for val in list_data:
    if val == P:
        a = i
    if val == Q:
        b = i
    i += 1

if a >= b:
    print(a-b)
else:
    print(b-a)
# Judge status: Accepted
k = 0
for i in input():
  k += i=="S" or -(k>0)
print(k*2)
# Judge status: Accepted
a, b,c, d = list(map(int, input().split()))
 
if (abs(a-b)<=d) and (abs(b-c)<=d) or (abs(a-c)<=d):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
s = input()
txt = []

for c in s:
    if c == 'B' and len(txt) > 0:
        txt.pop()
    else:
        txt.append(c)

print(''.join(txt))
# Judge status: Wrong Answer
n, m = map(int, input().split())
a = list(int(input()) for _ in range(m))

dp = [0] * (n+1)
dp[0] = 1

if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2, n+1):
    if i in a:
        continue
    dp[i] = dp[i-1] + dp[i - 2]
    dp[i] %= 1000000007

print(dp)
# Judge status: Accepted
N=int(input())
S=input()
R,G,B=0,0,0
ans=0
for i in range(N):
    if S[i]=='R':
        R+=1
    elif S[i]=='G':
        G+=1
    else:
        B+=1
ans+=R*G*B
f,s,t=0,1,2
while t<=N-1:
    i=0
    while i+t<=N-1:
        if S[f+i]!=S[s+i] and S[f+i]!=S[t+i] and S[s+i]!=S[t+i]:
            ans-=1
        i+=1
    s+=1
    t+=2
print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
  if i == 0:
    ans += b[a[i]-1]
  else:
    ans += b[a[i]-1]
    if a[i]-a[i-1] == 1:
      ans += c[a[i]-2]
print(ans)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(N):
  now = 0
  for j in range(N):
    if(i!=j):
      now = now ^ A[j] 
  ans.append(now)
print(ans)
# Judge status: Accepted
n = int(input())
x = list(map(int, input().split(' ')))
p = int(round(sum(x) / n))
r = 0
for i in x:
    r += (i - p) * (i - p)
print(r)
# Judge status: Accepted
N, R = map(int, input().split())

if N < 10:
  print(R + 100*(10-N))
else:
  print(R)
# Judge status: Accepted
s=input()

a=len(s)
s=[]
for n in range(0,a):
  s.append("x")
s="".join(s)
print(s)
# Judge status: Accepted
H,W,N=int(input()),int(input()),int(input())
print(-(-N//max(H,W)))
# Judge status: Wrong Answer
n=int(input())
w=list(map(int,input().split()))

a=[]

for i in range(0,n):
    ans=(w[:i])
    if 2*sum(ans)-sum(w)>=0:
        a.append(2*sum(ans)-sum(w))
        
print(min(a))
# Judge status: Accepted
x=input().split()
a=int(x[0])
b=int(x[1])
if a>0:
  print('Positive')
else:
  if b<0:
    if (b-a)%2==0:
      print('Negative')
    else:
      print('Positive')
  else:
    print('Zero')
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline

x = int(input())

print(x * 2 // 11 + 1)
# Judge status: Accepted
n = int(input())
hn = [int(i) for i in input().split()]
max_cnt, cnt = 0, 0
for i in range(1, n):
    if hn[i - 1] - hn[i] >= 0:
        cnt += 1
    else:
        cnt = 0
    if max_cnt < cnt:
        max_cnt = cnt        
print(max_cnt)
# Judge status: Accepted
n = int(input())
l = list(map(int, input().split()))
tot = sum(l)
flag = True
for l_i in l:
  if 2 * l_i >= tot:
    flag = False
    break
if flag:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
def solve(n, A):
    if A.count(0) > 0:
        return sum(map(abs, A))
    total = 0
    minval = 10 ** 9
    count = 0
    for a in A:
        total += abs(a)
        if a < 0:
            count += 1
        if abs(a) < minval:
            minval = abs(a)
    return total - (2 * minval if count % 2 == 1 else 0)

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))
# Judge status: Accepted
x,y = map(int,input().split())
li = list(map(int,input().split()))
from collections import deque
l = []
for i in range(len(li)):
    l.append((1+ li[i])/2)
from itertools import accumulate
a = list(accumulate(l))
M = a[y-1]
for i in range(len(a)-y):
    m = a[i+y] - a[i]
    if m > M:
        M = m
print(M)
# Judge status: Accepted
from collections import Counter

N,K = map(int,input().split())
A = list(map(int,input().split()))

C = Counter(A).most_common()

ans = 0
for i in range(len(C)):
    if i >= K:
        ans += C[i][1]

print(ans)
# Judge status: Accepted
S = list(input())
f = False
c = 0

for i  in range(len(S) - 1):
    # if i == len(S) - 2:
    #     break
    if S[i] != S[i + 1]:
        continue
    else:
        if S[i] == "0":
            S[i+1] = "1"
            c += 1
        else:
            S[i+1] = "0"
            c += 1

print(c)
# Judge status: Wrong Answer
sum=0
minb=124
for i in range(5):
    a=int(input())
    sum += a//10*10 if a%10==0 else a//10*10+10
    b=a%10
    minb = min(minb,b) if b!=0 else minb
print(sum-10+minb)
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
print("YES" if c-a<=b else "NO")
# Judge status: Accepted
import numpy
N = int(input())
a = int(numpy.ceil(N / 1000) * 1000 - N)
print(a)
# Judge status: Wrong Answer
k, a, b = map(int, input().split())

if k == 1:
    print(2)
elif k < a + 2 or b - a <= 2:
    print(1 + k)
else:
    cnt = (k - (a - 1)) // 2
    mod = (k - (a - 1)) % 2
    ans = (b - a)*cnt + a + mod
    print(ans)
# Judge status: Accepted
import datetime
date_str = "2019/04/30"
date_formatted = datetime.datetime.strptime(date_str, "%Y/%m/%d")
s = input()
s = datetime.datetime.strptime(s, "%Y/%m/%d")

if s <= date_formatted:
    print('Heisei')
else:
    print('TBD')
# Judge status: Wrong Answer
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a % b)

N = int(input())
T = [0] * N
for i in range(N):
    T[i] = int(input())
ans = 1
for i in range(N-1):
    ans *= (T[i] * T[i+1] // gcd(T[i], T[i+1]))
print(ans)
# Judge status: Accepted
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
cd=[list(map(int,input().split())) for i in range(m)]
def dist(list1,list2):
  return abs(list1[0]-list2[0])+abs(list1[1]-list2[1])
for human in ab:
  for i in range(m):
    if i==0:
      d=dist(human,cd[0])
      index=1
    else:
      d_new=dist(human,cd[i])
      if d>d_new:
        d=d_new
        index=i+1
  print(index)
# Judge status: Accepted
N = int(input())
alist = list(map(int, input().split()))
flag = 0
for i in range(0,N):
    if alist[i]%2 == 1:
        continue
    else:
        if alist[i]%3 == 0 or alist[i]%5 == 0:
            continue
        else:
            print("DENIED")
            flag = 1
            break
if flag == 0:
    print("APPROVED")
# Judge status: Accepted
import copy
import math

n, k = map(int,input().split())
a = list(map(int,input().split()))

ub = 10**9
lb = 0

while ub - lb > 10**-6:
    x = (ub + lb) / 2
    cnt = 0
    for i in a:
        cnt += math.ceil(i/x)
    if cnt <= n+k:
        ub = copy.deepcopy(x)
    else:
        lb = copy.deepcopy(x)
ans = round(ub, 6)
print(math.ceil(lb))
# Judge status: Wrong Answer
n,k = map(int,input().split())
l = n%k

if k !=1 and l == 0:
    if l >= abs(l-k):
        print(abs(l-k))
    else:
        print(l)
else:
    print(0)
# Judge status: Accepted
import math
H = int(input())

a = int(math.log(H,2))

print((2**(a+1))-1)
# Judge status: Accepted
a,b,n = map(int,input().split())
if n%b==0:n-=1
x = max((n//b)*b-1,n%b)
print(((a*x)//b)-(a*(x//b)))
# Judge status: Accepted
import bisect
import heapq
import numpy as np
N, M = map(int,input().split())
a = list(map(int,input().split()))
a = list((np.array(a))*(-1))
heapq.heapify(a)
for m in range(M):
    tgt = -heapq.heappop(a)
    heapq.heappush(a,-(tgt//2))
res = 0
for n in range(N):
    res += int(heapq.heappop(a))
print(-res)
# Judge status: Accepted
import itertools
import copy
from collections import deque
import heapq
n = int(input())
a = list(map(int,input().split()))
a.sort()
a = a[::-1]
ans = 1
if a[-1] == 0:
    print(0)
    exit()
for i in a:
    ans *= i
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
# Judge status: Wrong Answer
a = int(input())
b = int(input())
h = int(input())
result = (a + b) * h / 2
print(result)
# Judge status: Accepted
import math as ma

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

al = 360 * (h + m /60) /12
bl = m*6
rad = ma.radians(min(abs(bl - al), 360 - abs(bl - al)))
r = ma.sqrt(a**2 + b**2 -2*a*b*ma.cos(rad))
print(r)
# Judge status: Accepted
n, k = map(int, input().split())
ls = list(map(int, input().split()))

ls.sort()

if k == 0:
    print(sum(ls))
else:
    print(sum(ls[:(-1) * k]))
# Judge status: Accepted
n,m=map(int,input().split())
ans=0
for i in range(1,int(m**0.5)+1):
  if m%i>0:continue
  a=i
  b=m//i
  if a*n<=m:ans=max(ans,a)
  if b*n<=m:ans=max(ans,b)
print(ans)
# Judge status: Accepted
c = input()

vowel_list = ['a', 'i', 'u', 'e', 'o']

if (c in vowel_list):
    print('vowel')
else:
    print('consonant')
# Judge status: Accepted
x = int(input())
ans = 0
for i in range(1,100)[::-1]:
  for j in range(2,11)[::-1]:
    if i**j <= x:
      ans = max(ans, i**j)
print(ans)
# Judge status: Accepted
strlist = list(input())
findlist="qazwsxedcrfvtgbyhnujmikolp"
flist=list(findlist)
flag = "Yes"
for a in flist:
    if strlist.count(a) % 2:
        flag = "No"
print(flag)
# Judge status: Wrong Answer
N = int(input())
inputs = [int(input()) for i in range(N)]

points = [int(s) for s in inputs]
points_sorted = sorted(points)

get_point = sum(points)
non_10 = [x for x in points_sorted if (x % 10 != 0)]

if get_point % 10 != 0:
    print(get_point)
elif non_10 == []:
    print(0)
else:
    print(get_point - min(points_sorted))
# Judge status: Accepted
S = list(input())
ans = "yes"
for i in range(len(S)):
    ch = S[i]
    S[i] = "-1"
    if ch in S:
        ans = "no"
        break
print(ans)
# Judge status: Accepted
a,b,c=map(int,input().split())
print('YES' if b-a == c-b else 'NO')
# Judge status: Wrong Answer
a,b = map(int,input().split())
if a+b % 2 == 1:
    print("IMPOSSIBLE")
else:
     print(int((a+b)/2))
# Judge status: Accepted
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    S = list(S)
    print('Yes'if S[2] == S[3] and S[4] == S[5] else'No')



if __name__ == '__main__':
    main()
# Judge status: Accepted
N,T = map(int,input().split())
CT = [list(map(int,input().split())) for i in range(N)]
CT = list(filter(lambda x:x[1]<=T,CT))
if len(CT)==0:
    print('TLE')
else:
    print(min(CT)[0])
# Judge status: Wrong Answer
f_1 = {1,3,5,7,8,10,12}
f_2 = {4,6,9,11}

x, y = map(int, input().split())
if (x in f_1) and (y in f_2):
  print("Yes")
elif (x in f_2) and (y in f_2):
  print("Yes")
else:
  print("No")
# Judge status: Accepted
N,R = map(int,input().split())
if N < 10:
    print(100*(10-N)+R)
else:
    print(R)
# Judge status: Wrong Answer
S = input()
T = ("2019/05/01")
if S[0:-1] == T:
  print("TBD")
else:
  print("Heisei")
# Judge status: Accepted
import math
def f(x):
    return math.floor(a*x/b) - a*math.floor(x/b)

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

if b-1<=n:
    ans=f(b-1)
    print(ans)
else:
    ans=f(n)
    print(ans)
# Judge status: Accepted
x = int(input())
ans = 1000 * (x // 500)
ans += 5 * ((x % 500) // 5)
print(ans)
# Judge status: Accepted
n = int(input())
print(n + (n * n) + (n * n * n))
# Judge status: Accepted
import math

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

c = (h * 60 * 0.5) + (m * 0.5)
d = m * 6

if c > d:
  e = c - d
else:
  e = d - c

ans = (a * a) + (b * b) - 2 * a * b * math.cos(math.radians(e))
print(math.sqrt(ans))
# Judge status: Accepted
X, Y, Z = map(int,input().split())

X = X - Z

print(X//(Y + Z))
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
odd = a[0::2]
even = a[1::2]
ans = []
if n%2 == 0:
	even.reverse()
	ans.extend(even)
	ans.extend(odd)
	print (*ans)
else:
	odd.reverse()
	ans.extend(odd)
	ans.extend(even)
	print (*ans)
# Judge status: Wrong Answer
N = int(input())

for i in range(1,10):
  for j in range(1,10):
    if N == i*j:
      print("Yes")
    elif i*j ==81:
      print("No")
# Judge status: Accepted
import itertools

n = int(input())
lis = []
for i in range(n):
    x, y = map(int, input().split())
    lis.append((x, y))

LIS = [i for i in range(n)]

big_lis = list(itertools.permutations(LIS))
L = len(big_lis)


def sai(i, j):
    return (lis[A[i + 1]][j] - lis[A[i]][j]) ** 2


keep = 0
ANS = 0
for i in range(L):
    A = list(big_lis[i])
    keep = 0
    for j in range(n - 1):
        keep += (sai(j, 0) + sai(j, 1)) ** (1 / 2)
    ANS += keep
print(ANS / L)
# Judge status: Wrong Answer
a,b=map(int,input().split())
print(((a+b)+2-1)/2)
# Judge status: Accepted
A, B, K = map(int, input().split())

cd = []

if A > B:
  nums = [i for i in range(1, B+1)]
elif A < B:
  nums = [i for i in range(1, A+1)]
else:
  nums = [i for i in range(1, A+1)]

for i in nums:
  if A % i == 0 and B % i == 0:
    cd.append(i)
print(cd[-K])
# Judge status: Accepted
x,y = map(int, input().split())
ans=0
i=x
while i<=y:
    ans+=1
    i*=2
    
print(ans)
# Judge status: Accepted
n = int(input())
x = list(map(int, input().split()))
x_sorted = sorted(x)

cs = x_sorted[n // 2 - 1]
cb = x_sorted[n // 2]

for i, v in enumerate(x):
    if v <= cs:
        print(cb)
    else:
        print(cs)
# Judge status: Wrong Answer
n = int(input())

wk =[]
for i in range(n):
    wk.append(list(map(int,input().split())))
xl = sorted(wk, key=lambda x:x[0])

xx = []
ll = []
cnt = 0

for i in range(n):
    x,l = xl[i][0],xl[i][1]

    if i == 0 or xx[cnt-1] + ll[cnt-1] -1 <  x - l:
        xx.append(x)
        ll.append(l)
        cnt +=1

print(len(xx))
# Judge status: Accepted
n=int(input())
ans=n//11*2
n%=11
if 1<=n<=6:ans+=1
if 7<=n:ans+=2
print(ans)
# Judge status: Accepted
n = int(input())
for a in range(-200, 200):
  for b in range(-200, 200):
    if n == a ** 5 - b ** 5:
      print(a)
      print(b)
      quit()
# Judge status: Accepted
a=list(map(int,input().split()))
a.sort(reverse=True)
if a[0]==a[1]+a[2]:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
n = int(input())

l = [0 for _ in range(n+1)]
l[1] = 1

for i in range(n+1):
    for j in range(i-1, 0, -1):
        if i % j == 0:
            l[i] = l[j] + 1
            break

ans = 0
for k in range(n+1):
    ans += (k * l[k])

print(ans)
# Judge status: Wrong Answer
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  s=list(input())
  t=list(input())
  
  s.sort()
  t.sort(reverse=True)
  if s==t:
    print("No")
    return
  if s in t:
    print("Yes")
    return
  
#  if(len(s)<len(t)):
#    print("Yes")
#    return
  for i in range(min(len(s),len(t))):
    if ord(s[i])>ord(t[i]):
      print("No")
      return
    elif ord(s[i])<ord(t[i]):
      print("Yes")
      return
  print("No")
  return
main()
# Judge status: Wrong Answer
n,m=map(int,input().split())
e=[[]for _ in range(n)]
py=[]
for _ in range(m):
  p,y=map(int,input().split())
  py.append((p,y))
  e[p-1].append(y)
for i in range(n):e[i].sort()
xy=lambda x,y:x*1000000+y
d={}
for i in range(n):
  for j in range(len(e[i])):
    d[xy(i+1,e[i][j])]=str(i+1).zfill(6)+str(j+1).zfill(6)
for p,y in py:
  print(d[xy(p,y)])
# Judge status: Accepted
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


n,a,b = readints()

if (b-a)%2==0:
    print((b-a)//2)
else:
    print(min(n-b+(b-a)//2+1,a-1+(b-a)//2+1))
# Judge status: Accepted
n, T = map(int, input().split())
cost = []
time = []
element = []
ans = 1000

for i in range(n):
    c, t = map(int, input().split())
    cost.append(c)
    time.append(t)

for c, t in zip(cost, time):
    if t <= T:
        element.append(c)

if len(element) == 0:
    print('TLE')
else:
    ans = min(element)
    print(ans)
# Judge status: Accepted
from bisect import bisect_left
n, k = map(int, input().split())
candles = list(map(int, input().split()))
point_zero = bisect_left(candles, 0)
candles.insert(point_zero, 0)
ans = float('inf')
for i in range(min(k, point_zero) + 1):
    left = point_zero - i
    right = point_zero + k - i
    if (0 <= left) and (right < n + 1):
        dis = -candles[left] + candles[right] + min(-candles[left], candles[right])
        ans = min(ans, dis)
print(ans)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))

odd=0
ni=0
si=0
for x in a:
    if x%4==0:
        si+=1
    elif x%2==0:
        ni+=1
    else:
        odd+=1
ni=ni%2
if odd+ni<=si+1:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
a=list(map(int,input().split()))
print('NYoe s'[sum(a)/2 in a::2])
# Judge status: Wrong Answer
x,y=map(int,input().split())
if x==0:
  if y<0:
    print(-1*y+1)
  else:
    print(y)
    
elif x>0:
  if -1*x<y<x:
    print(y+x+1)
  elif x<y:
    print(y-x)
  else:
    print(-1*y-x+1)
    
else:
  if x<y<-1*x:
    print(y-x)
  elif y<x:
    print(-1*y+x+2)
  else:
    print(y+x+1)
# Judge status: Accepted
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, C, X, Y = map(int, readline().split())

ans = 10 ** 10
for c in range(2 * 10 ** 5 + 1):
    a = X - c // 2
    b = Y - c // 2
    if a < 0:
        a = 0
    if b < 0:
        b = 0
    ans = min(ans, A * a + B * b + C * c)
print(ans)
# Judge status: Wrong Answer
N = int(input())
S = list(input())

T = []
while S and S[-1] == '(':
    T.append(S.pop())
S = S[::-1]
T = T + [')'] * len(T)

H = []
while S and S[-1] == ')':
    H.append(S.pop())
S = S[::-1]
H = ['('] * len(H) + H

l = S.count('(')
r = S.count(')')
d = l - r

S = H + S + T

if d > 0:
    S = S + [')'] * d
if d < 0:
    S = ['('] * (-d) + S

print(''.join(S))
# Judge status: Wrong Answer
from collections import deque,defaultdict

n,m=map(int, input().split())
ab = [deque() for i in range(m+1)]

for i in range(n):
    a,b=map(int, input().split())
    if(not a>m):
        ab[a-1].append(-1*b)
res = 0
cnt = 0

for i in range(m):
    if(len(ab[i])>0):
        tmp = min(ab[i])*-1
        ab[i].pop()
        res+=tmp
    ab[i+1]+=(ab[i])
print(res)
# Judge status: Wrong Answer
d={1:1,3:1,5:1,7:1,8:1,10:1,12:1,4:2,6:2,9:2,11:2,2:3}
a=list(map(int,input().split()))
if d[a[0]]==d[a[0]]: 
    print('Yes')
else: 
    print('No')
# Judge status: Accepted
N, M = map(int, input().split())
if N == 1 and M == 1:
    print(1)
elif (N == 1 and M >= 2) or (M == 1 and N >= 2):
    print(max(N, M) - 2)
else:
    print((N - 2) * (M - 2))
# Judge status: Accepted
s = input()
t = sorted(s)

if t[0] == t[1] and t[2] == t[3] and t[0] != t[2]:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
a = list(map(int,input().split()))
b = a[2] * 60 + a[3] - a[0] * 60 - a[1] - a[4]
print(b)
# Judge status: Wrong Answer
N = str(input())

# print(N)

if '7' in N :
  print("YES")
else:
  print("NO")
# Judge status: Accepted
def main():
    a, b, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    xyc = [list(map(int, input().split())) for _ in [0]*m]
    ans = min(a)+min(b)
    for x, y, c in xyc:
        ans = min(ans, a[x-1]+b[y-1]-c)
    print(ans)


main()