Harryxun/stf_run huggingface dataset:
import collections
N=int(input())
L=list(map(int,input().split()))
c = collections.Counter(L)
A=list(c.keys())
B=list(c.values())
R=list()
for i in range(len(A)):
  if B[i]>=2:
    R.append([A[i],B[i]])
R=sorted(R,reverse=True)
if R[0][1]>=4:
  print(R[0][0]**2)
elif len(R)<2:
  print(0)
else:
  print(R[0][0]*R[1][0])

### FIXED CODE ###

import collections
N=int(input())
L=list(map(int,input().split()))
c = collections.Counter(L)
A=list(c.keys())
B=list(c.values())
R=list()
for i in range(len(A)):
  if B[i]>=2:
    R.append([A[i],B[i]])
R=sorted(R,reverse=True)
if len(R)==0:
  print(0)
  exit()
if R[0][1]>=4:
  print(R[0][0]**2)
elif len(R)<2:
  print(0)
else:
  print(R[0][0]*R[1][0])
n_m_k = input().split()
n = int(n_m_k[0])
m = int(n_m_k[1])
k = int(n_m_k[2])

a_str_list = input().split()
a_int_list = [int(x) for x in a_str_list]

b_str_list = input().split()
b_int_list = [int(x) for x in b_str_list]

sum_t = 0
cnt_a = 0
cnt_b = 0

len_a = len(a_int_list)
len_b = len(b_int_list)
while(1):
    if((cnt_a != len_a) and (cnt_b != len_b)):
        if(a_int_list[cnt_a] < b_int_list[cnt_b]):
            sum_t += a_int_list[cnt_a]
            if(sum_t <= k):
                cnt_a += 1
            else:
                break
        elif(a_int_list[cnt_a] > b_int_list[cnt_b]):
            sum_t += b_int_list[cnt_b]
            if(sum_t <= k):
                cnt_b += 1
            else:
                break
        #
        elif(a_int_list[cnt_a] == b_int_list[cnt_b]):
            if(a_int_list[cnt_a + 1] < b_int_list[cnt_b + 1]):
                sum_t += a_int_list[cnt_a]
                if(sum_t <= k):
                    cnt_a += 1
                else:
                    break
            elif(a_int_list[cnt_a + 1] > b_int_list[cnt_b + 1]):
                sum_t += b_int_list[cnt_b]
                if(sum_t <= k):
                    cnt_b += 1
                else:
                    break
        #

    elif(cnt_a < len_a):
        sum_t += a_int_list[cnt_a]
        if(sum_t <= k):
            cnt_a += 1
        else:
            break
    elif(cnt_b < len_b):
        sum_t += b_int_list[cnt_b]
        if(sum_t <= k):
            cnt_b += 1
        else:
            break
    else:
        break

print(cnt_a + cnt_b)

### FIXED CODE ###

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

a = [0]
b = [0]

for i in range(N):
    a.append(a[i] + A[i])

for j in range(M):
    b.append(b[j] + B[j])

ans = 0
j = M

for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(i + j, ans)

print(ans)
# B - Stone Monument
N, M = map(int,input().split())

tmp= (M-N)*( M-N+1)/2

ans( tmp-N)

### FIXED CODE ###

# B - Stone Monument
a,b =map(int,input().split())

tmp= (b-a)*( b-a-1)/2

print(  int(tmp-a))
import math
a,b,x=map(int,input().split())
if x==a*a*b:
  print(0)
elif x/a>=a*b/2:
  tangent= 2*b/a-2*x/a**3
else:
  tangent=a*b*b /(2*x)
print(math.degrees(math.atan(tangent)))


### FIXED CODE ###

import math
a,b,x=map(int,input().split())
if x/a>=a*b/2:
  tangent= 2*b/a-2*x/a**3
else:
  tangent=a*b*b /(2*x)
print(math.degrees(math.atan(tangent)))
X,Y = map(int,input().split())

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def combi(n,r,mod=10**9+7):
    fac = [0]*(n+1)
    fac[0] = 1
    fac[1] = 1
    for i in range(2,n+1):
        fac[i] = fac[i-1] * i % mod
    return( ( fac[n] * modinv(fac[r]) )%mod * modinv(fac[n-r]) % mod)

if ( X + Y ) % 3 != 0:
    print(0)
else:
    n = X - (X + Y)//3
    m = (X + Y)//3 - n
    print(combi(n+m,m))

### FIXED CODE ###

X,Y = map(int,input().split())

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def combi(n,r,mod=10**9+7):
    fac = [0]*(n+1)
    fac[0] = 1
    fac[1] = 1
    for i in range(2,n+1):
        fac[i] = fac[i-1] * i % mod
    return( ( fac[n] * modinv(fac[r]) )%mod * modinv(fac[n-r]) % mod)

if (X+Y) % 3 != 0 or X > 2*Y or Y > 2*X:
    print(0)
else:
    n = X - (X + Y)//3
    m = (X + Y)//3 - n
    print(combi(n+m,m))
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
N,K,Q=map(int,input().split())

A=[int(input()) for _ in range(Q)]
S=[K-Q]*N


for i in range(K):
	S[A[i]-1]+=1	
	
for k in range(N):
	if S[k]>0:
		print("Yes")
	else:
		print("No")
	

### FIXED CODE ###

import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
N,K,Q=map(int,input().split())

A=[int(input()) for _ in range(Q)]
S=[K-Q]*N


for i in range(Q):
	S[A[i]-1]+=1	
	
for k in range(N):
	if S[k]>0:
		print("Yes")
	else:
		print("No")
a,b,c = map(int,input())
if c>=a and c<=b:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a,b,c = map(int,input().split())
print("Yes" if a<=c<=b else "No")
i = input_raw()
print int(i) ** 3

### FIXED CODE ###

i = int(input())
print i * i * i
N=int(input())
for h in range(3501):
  for n in range(3501):
    if (N*h*n)%(4*h*n-N*n-N*h)==0:
      print(h,n,(N*h*n)%(4*h*n-N*n-N*h))

### FIXED CODE ###

N=int(input())
for h in range(1,3501):
  for n in range(1,3501):
    if 4*h*n-N*n-N*h>0:
      if (N*h*n)%(4*h*n-N*n-N*h)==0:
        print(h,n,(N*h*n)//(4*h*n-N*n-N*h))
        exit()
import math

# input
#
# n = 5
# k = 10
# a = [1, 2, 3, 2, 3]

n, k = map(int, input().split())
a = [int(ai) for ai in input().split()]

# make jumpto
#
# 0 -> 6 (5)
# 1 -> 4 (2)
# 2 -> 5 (2)
# 3 -> 7 (3)
# 4 -> 8 (3)

jumpto = [[-1] * n]
la = -1
li = -1
for (ca, ci) in sorted(zip(a, range(n))):
    if ca == la:
        jumpto[0][ci] = jumpto[0][li] + li - ci
        jumpto[0][li] = ci - li
    else:
        jumpto[0][ci] = n
    la = ca
    li = ci

# doubling jumpto
#
# 0 -> 6 ->  9 (8)
# 1 -> 4 ->  8 (6)
# 2 -> 5 -> 11 (8)
# 3 -> 7 -> 10 (6)
# 4 -> 8 -> 12 (7)
#
# 0 -> 6 ->  9 -> 13 -> 17  (16)
# 1 -> 4 ->  8 -> 12 -> 15  (13)
# 2 -> 5 -> 11 -> 14 -> 18  (15)
# 3 -> 7 -> 10 -> 16 -> 19  (15)
# 4 -> 8 -> 12 -> 15 -> 21  (16)

levels = int(math.log2(k))
for l in range(1, levels + 1):
    jumpto.append([-1] * n)
    for i in range(n):
        f = jumpto[l - 1][i]
        s = jumpto[l - 1][(i + f + 1) % n]
        jumpto[l][i] = f + 1 + s

# step1
s = 0
while True:
    jumped = False
    for l in range(levels, -1, -1):
        if s + jumpto[l][s % n] < n * k:
            s += jumpto[l][s % n] + 1
            jumped = True
            break
    if not jumped:
        break

# step2
ret = []
while s < n * k:
    if s + jumpto[0][s % n] < n * k:
        s = s + jumpto[0][s % n] + 1
    else:
        ret.append(str(a[s % n]))
        s += 1

print(' '.join(ret))


### FIXED CODE ###

import math

# input
#
# n = 5
# k = 10
# a = [1, 2, 3, 2, 3]

n, k = map(int, input().split())
a = [int(ai) for ai in input().split()]

# make jumpto
#
# 0 -> 6 (5)
# 1 -> 4 (2)
# 2 -> 5 (2)
# 3 -> 7 (3)
# 4 -> 8 (3)

jumpto = [[-1] * n]
la = -1
li = -1
for (ca, ci) in sorted(zip(a, range(n))):
    if ca == la:
        jumpto[0][ci] = jumpto[0][li] + li - ci
        jumpto[0][li] = ci - li
    else:
        jumpto[0][ci] = n
    la = ca
    li = ci

# doubling jumpto
#
# 0 -> 6 ->  9 (8)
# 1 -> 4 ->  8 (6)
# 2 -> 5 -> 11 (8)
# 3 -> 7 -> 10 (6)
# 4 -> 8 -> 12 (7)
#
# 0 -> 6 ->  9 -> 13 -> 17  (16)
# 1 -> 4 ->  8 -> 12 -> 15  (13)
# 2 -> 5 -> 11 -> 14 -> 18  (15)
# 3 -> 7 -> 10 -> 16 -> 19  (15)
# 4 -> 8 -> 12 -> 15 -> 21  (16)

levels = int(math.log(k, 2))
for l in range(1, levels + 1):
    jumpto.append([-1] * n)
    for i in range(n):
        f = jumpto[l - 1][i]
        s = jumpto[l - 1][(i + f + 1) % n]
        jumpto[l][i] = f + 1 + s

# step1
s = 0
while True:
    jumped = False
    for l in range(levels, -1, -1):
        if s + jumpto[l][s % n] < n * k:
            s += jumpto[l][s % n] + 1
            jumped = True
            break
    if not jumped:
        break

# step2
ret = []
while s < n * k:
    if s + jumpto[0][s % n] < n * k:
        s = s + jumpto[0][s % n] + 1
    else:
        ret.append(str(a[s % n]))
        s += 1

print(' '.join(ret))
n = int(input())
#m = int(input())
k = int(input())
#n, m = map(int, input().split())
#n, m, k = map(int, input().split())
#a = list(map(int, input().split()))
#table = []
'''
for i in range h:
    temp = list(map(int, input().split()))
    table.append(temp)
'''
print(n-k+1)

### FIXED CODE ###

#n = int(input())
#m = int(input())
#k = int(input())
#n, m = map(int, input().split())
n,  k = map(int, input().split())
#a = list(map(int, input().split()))
#table = []
'''
for i in range h:
    temp = list(map(int, input().split()))
    table.append(temp)
'''
print(n-k+1)
n = int(input())
s = list(input())
for i in s:
   if i =="I":
      n += 1
    else:
       n -= 1
print(n)

### FIXED CODE ###

n = int(input())
s = list(input())
x = 0
l = []
l.append(x)
for i in s:
   if i =="I":
      x += 1
   elif i =="D":
      x -= 1
   l.append(x)
print(max(l))
N=int(input())
List=list(map(int,input().split()))
a=0
List.sort()
for i in range(len(List)):
  a= (a+List[i])/2
print(a)

### FIXED CODE ###

a=int(input())
s=input()
if a>=3200:
  print(s)
else:
  print('red')
s = list(map(int, input()))
if s == [1, 4, 7, 9]:
  print("YES")
else:
  print("NO")   

### FIXED CODE ###

s = list(map(int, input().split()))
if sorted(s) == [1, 4, 7, 9]:
  print("YES")
else:
  print("NO")
N,W=map(int,input().split())
w=[]
v=[]
for i in range(N):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
dp=[[0 for i in range(W+1)] for j in range(N+1)]
for i in range(N):
    for j in range(W+1):
        if j>=w[i]:
            dp[i+1][j]=max(dp[i][j-w[i]]+v[i],dp[i][w])
        else:
            dp[i+1][j]=dp[i][j]
print(dp[N][W])

### FIXED CODE ###

N,W=map(int,input().split())
taple=[]
for i in range(N):
    w,v=map(int,input().split())
    taple.append((w,v))
dp=[[10**22]*(N*(10**3)+1) for i in range(N+1)]
dp[0][0]=0
for i in range(1,N+1):
    w,v=taple[i-1]
    for j in range(N*(10**3)+1):
        if j>=v:
            dp[i][j]=min(dp[i-1][j-v]+w,dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
for i in range(N*(10**3),-1,-1):
    if dp[N][i]<=W:
        print(i)
        break
import math
import queue

N = int(input())
As = sorted(list(map(int, input().split())))

ques = [queue.Queue() for i in range(N)]

for i, Ai in enumerate(As):
    qi = ques[i]
    for j in range(1,int(Ai/2)+1) :
        if (Ai % j == 0) :
            qi.put(j)
    
flag = True
while flag:
    for i, qi in enumerate(ques):
        if(qi.empty()) :
            As[i] = As[-1]
            flag = False
            break
        else :
            qi.get()

min_num = As[0]
gcd_num = math.gcd(As[0], As[1])
for i in range(2,N) :
    #改善の余地あり
    gcd_num = math.gcd(gcd_num, As[i])
    if (gcd_num==1) :
        break

print(gcd_num)

### FIXED CODE ###

#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")

def main():
    N = I()
    A = LI()

    forward = list(itertools.accumulate(A, math.gcd))
    backward = list(itertools.accumulate(A[::-1], math.gcd))[::-1]

    ans = max(backward[1], forward[-2])

    for i in range(1, N - 1):
        ans = max(ans, math.gcd(forward[i - 1], backward[i + 1]))
    print(ans)


if __name__ == '__main__':
    main()
import sys
input = sys.stdin.readline

def binary_search_int(ok, ng, solve):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if solve(mid):
            ok = mid
        else:
            ng = mid
    return ok, ng

##############################################################

def solve(x):
    """ ある点 x を境にして True と False が二分されるような関数"""
    return N - K*x >= 0

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

a, b = binary_search_int(0, 10**18, solve)
print(min(abs(N-a*K), abs(N-b*K)))


### FIXED CODE ###

K = int(input())

N = [0]

for _ in range(K):
    i = 0
    while i < len(N) and N[i] == 9:
        i += 1
    while i+1 < len(N) and N[i] == N[i+1]+1:
        i += 1
    if i == len(N):
        N = [0]*len(N) + [1]
    else:
        N[i] += 1
        i -= 1
        while i >= 0:
            N[i] = max(N[i+1]-1,0)
            i -= 1

print(*reversed(N),sep='')
n=int(input())
rem=str(n)
l1=[2,4,5,7,9]
l2=[0,1,6,8]

if int(n[-1:]) in l1:
  print('hon')
if int(n[-1:]) in l2:
  print('bon')
if int(n[-1:]) == 3:
  print('pon')
  

### FIXED CODE ###

n = input()
if n[-1:] == str(2) or  n[-1:] ==  str(4)  or  n[-1:] ==  str(5) or  n[-1:] == str(7) or  n[-1:] == str(9):
  print('hon')
if (n[-1:]) == str(0) or  n[-1:] == str(1) or  n[-1:] == str(6) or  n[-1:] == str(8):
  
  print('pon')
if (n[-1:]) == str(3):
  print('bon')
n=int(input())
h=[int(x) for x in input().split()]

ans_list=[]

def A(i,n,h,ans_list):
    ans=0
    if n==1:
        ans_list.append(0)
    else:
        for j in range(i,n-1):
            if h[j]>=h[j+1]:
                ans+=1
                if j==n-2:
                    ans_list.append(ans)
                    break
            else:
                ans_list.append(ans)
                A(j+1,n,h,ans_list)
                break
        
A(0,n,h,ans_list)
print(max(ans_list))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
n=int(input())
h=[int(x) for x in input().split()]

ans_list=[]

def A(i,n,h,ans_list):
    ans=0
    for j in range(i,n-1):
        if h[j]>=h[j+1]:
            ans+=1
            if j==n-2:
                ans_list.append(ans)
                break
        else:
            ans_list.append(ans)
            A(j+1,n,h,ans_list)
            break
        
if n==1:
    print(0)
else:
    A(0,n,h,ans_list)
    print(max(ans_list))
from collections import deque

n,m=map(int,input().split())
l=list(map(int,input().split()))
l=[i/2 for i in l]
if n==1:
  if (m//l[0])%2==0:
    print(int((m//l[0])/2))
  else:
    print(int((m//l[0]+1)/2))
  exit()
  
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

l=set(l)
a1=l.pop()
a2=l.pop()
g=gcd(a1,a2)
lcm=g*(a1/g)*(a2/g)
d=1

while l:
  a=l.pop()
  d=gcd(lcm,a)
  lcm=d*(a/d)*(g/d)
  

if lcm>m:
  print(0)
  exit()
for a in l:
  if (lcm/a)%2==0:
    print(0)
    break
else:
  if (m//lcm)%2==0:
    print(int((m//lcm)/2))
  else:
    print(int((m//lcm+1)/2))

### FIXED CODE ###

#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))

def lcm(a,b):
    g=math.gcd(a,b)
    return b*(a//g)
l=a[0]//2
for i in range(n):
    r=a[i]//2
    l=lcm(l,r)
for i in range(n):
    if (l//(a[i]//2))%2==0:
        print(0)
        exit()
res=m//l
print((res+1)//2)
from collections import defaultdict

parameter = list(map(int, input().split()))
n, k = parameter[0], parameter[1]

balls = list(map(int, input().split()))

numbers = defaultdict(lambda: 0)
for b in balls:
    numbers[b] += 1

if len(numbers) == k:
    print(0)

else:
    sort_number = sorted(numbers.items(), key=lambda x:x[1], reverse=True)
    answer = n - sum([sort_number[i][1] for i in range(k)])
    print(answer)

### FIXED CODE ###

from collections import defaultdict

parameter = list(map(int, input().split()))
n, k = parameter[0], parameter[1]

balls = list(map(int, input().split()))

numbers = defaultdict(lambda: 0)
for b in balls:
    numbers[b] += 1

k = min(k, len(numbers))

sort_number = sorted(numbers.items(), key=lambda x:x[1], reverse=True)
answer = n - sum([sort_number[i][1] for i in range(k)])
print(answer)
N = int(input())
S = list(map(int,input().split()))
ANS = 0
while True:
    S.sort()
    if S[0] == 1:
        ANS += 1
        break
    if len(S) == 1:
        ANS += S[0]
        break
    elif S[1] % S[0] == 0:
        S.pop(1)
    else:
        S.pop(1)
        S.append((S[1] % S[0]))
        
print(ANS)

### FIXED CODE ###

import copy 

def gcd(a,b):
    if b > a:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a

N = int(input())
T = list(map(int,input().split()))
T.sort()
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))
if len(T) == 2:
    ANS = max(T[0],T[1])
elif F == 0:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANS = max(ANSU,ANSV)
    
else:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(F)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
        
print(ANS)
n = int(input())
p = 0
for _ in n:
  i,j = [int(k) for k in input().split()]
  p += j-i+1
print(p)

### FIXED CODE ###

n = int(input())
p = 0
for _ in range(n):
  i,j = [int(k) for k in input().split()]
  p += j-i+1
print(p)
import sys
sys.setrecursionlimit(700000)
from math import factorial
N,K = map(int, input().split())
mod = 10**9 + 7
for i in range(1,K+1):
    try:
        comb = int(factorial(K-1) / factorial(i-1) / factorial(K-i) % mod)
    except ValueError:
        comb = 1
    try:
        sec = int(factorial(N-K+1) / factorial(N-K-i+1) / factorial(i) % mod)
    except ValueError:
        sec = 1
    print((comb * sec)%mod)

### FIXED CODE ###

from math import factorial
N,K = map(int, input().split())
mod = 10**9 + 7
def com(n,r):
    if n<r:
        return 0
    return int(factorial(n) // factorial(r) // factorial(n-r))
for i in range(1,K+1):
    comb = com(N-K+1,i)
    sec = com(K-1,i-1)
    print((comb * sec)%mod)
W = input()

while True:
    line = input()
    if line == 'END_OF_TEXT':
        break

    for s in line.lower().split():
        if s == W:
            count += 1

print(count)

### FIXED CODE ###

W = input()

count = 0
while True:
    line = input()
    if line == 'END_OF_TEXT':
        break

    for s in line.lower().split():
        if s == W:
            count += 1

print(count)
A, B, M = 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])

print(min(list))

### FIXED CODE ###

A, B, M = 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)
s = input()
pos = 0
cnt = 0
if len(s) < 3:
    print(0)
else:
    while(True):
        if s[pos:pos+3] == "ABC":
            s = s[:pos] + "BCA" + s[pos+3:]
            if pos > 0:
                pos -= 1
            cnt += 1
        else:
            if s[pos+1:pos+3] == "AB":
                pos += 1
            elif s[pos+2:pos+3] == "A":
                pos += 2
            else
                pos += 3
        if pos >= len(s)-2:
            break
    print(cnt)


### FIXED CODE ###

s = input()
pos = 0
cnt = 0
acnt = 0
if len(s) < 3:
    print(0)
else:
    while(True):
        if s[pos:pos+2] == "BC" and acnt > 0:
            pos += 2
            cnt += acnt
            # print(s, s[pos:pos+2], cnt, pos)
        else:
            if s[pos] == "A":
                acnt += 1
            else:
                acnt = 0
            pos += 1
        if pos >= len(s)-1:
            break
    print(cnt)
h,w = map(int,input(),split())
for i in range(h):
    a = input().split()
    for j in range(w):
        if a[j] == "snuke":
            ans = chr(ord('A') + j)+str(i)

print(ans)

### FIXED CODE ###

H, W = map(int, input().split())
S = [list(input().split()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == 'snuke':
            print(chr(ord('A') + j) + str(1 + i))
            break
n, k, s = map(int, input().split())
a = []
for _ in range(k):
        a.append(str(s))
for _ in range(n-k):
  if s != 1000000000
  	a.append(str(s+1))
  else:
    a.append(str(s-1))
ans = ' '.join(a)
print(ans)

### FIXED CODE ###

n, k, s = map(int, input().split())
a = []
for _ in range(k):
        a.append(str(s))
for _ in range(n-k):
  if s != 1000000000:
  	a.append(str(s+1))
  else:
    a.append(str(s-1))
ans = ' '.join(a)
print(ans)
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
ans = [[0]*5 for i in range(h)]
for i in range(h):
         for j in range(w):
                  if s[i][j] == "#":
                           for k in range(max(0,i-1),min(h,(i+1)+1)):
                                    for l in range(max(0,j-1),min(w,(j+1)+1)):
                                             ans[k][l] += 1
for i in range(h):
         for j in range(w):
                  if s[i][j] == "#":
                           ans [i][j] = "#"
for i in range(h):
         answer = list(map(str,ans[i]))
         answer=''.join(answer)
         print(answer)



### FIXED CODE ###

h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
ans = [[0]*w for i in range(h)]
for i in range(h):
         for j in range(w):
                  if s[i][j] == "#":
                           for k in range(max(0,i-1),min(h,(i+1)+1)):
                                    for l in range(max(0,j-1),min(w,(j+1)+1)):
                                             ans[k][l] += 1
for i in range(h):
         for j in range(w):
                  if s[i][j] == "#":
                           ans [i][j] = "#"
for i in range(h):
         answer = list(map(str,ans[i]))
         answer=''.join(answer)
         print(answer)
counter=0
a,b,c=map(int,input().split())
for i in range(a,b):
    if((c%i)==0) counter=counter+1
print(f"{counter}")



### FIXED CODE ###

counter=0
a,b,c=map(int,input().split())
for i in range(a,b+1):
    if((c%i)==0):
        counter=counter+1
print(f"{counter}")
from collections import deque
N,M = list(map(int,input().split(" ")))
AB =  [list(map(int,input().split(" "))) for _ in range(M)]
links = [[] for i in range(M+1)]

for a,b in AB:
  links[a].append(b)
  links[b].append(a)

result = [-1] * (N+1)
q = deque([1])
while q:
  i = q.popleft()
  for j in links[i]:
    if result[j] == -1:
      result[j] = i
      q.append(j)
      
print('Yes')
print('\n'.join(str(i) for i in result[2:]))



### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]

links = [[] for _ in range(N + 1)]
for a, b in AB:
    links[a].append(b)
    links[b].append(a)

result = [-1] * (N + 1)
q = deque([1])
while q:
    i = q.popleft()
    for j in links[i]:
        if result[j] == -1:
            result[j] = i
            q.append(j)
print('Yes')
print('\n'.join(str(i) for i in result[2:]))