Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
s=set(a)
data=[]
for i in s:
  p=a.count(i)
  if p>=2:
    data.append([i,p//2])
data.sort(reverse=True)
h=0
w=0
for i in data:
  if i[1]>=2:
    if h==0:
      h=i[0]
    if w==0:
      w=i[0]
  else:
    if h==0:
      h=i[0]
    elif h!=0 and w==0:
      w=i[0]
print(h*w)

### FIXED CODE ###

from collections import Counter
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
A=Counter(a)
s=set(a)
S=sorted(list(s))
S.reverse()
h=0
w=0
for i in S:
  res=A[i]
  if res>=4:
    if h==0:
      h=i
    if w==0:
      w=i
  elif 2<=res<4:
    if w==0:
      w=i
    elif w!=0 and h==0:
      h=i
print(h*w)
### BUGGY CODE ###

S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
reversecount = 0
for x in query:
    if int(x[0]) == 1:
        reversecount += 1
    else:
        if (int(x[1]) == 1 and (reversecount % 2 == 0)) or (int(x[1]) == 2 and (reversecount % 2 == 1)):
            S = x[2] + S
        else:
            S = S + x[2]
if reversecount % 2 == 1:
    S = S[::-1]
print(S)

### FIXED CODE ###

from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
reversecount = 0
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        reversecount += 1
    else:
        if (int(x[1]) == 1 and (reversecount % 2 == 0)) or (int(x[1]) == 2 and (reversecount % 2 == 1)):
            d.appendleft(x[2])
        else:
            d.append(x[2])
if reversecount % 2 == 1:
    d.reverse()
print(*d, sep='')
### BUGGY CODE ###

L, R = map(int,input().split())

new_list = []
for i in range(L,R):
    for j in range(i+1, R+1):
        k = i*j
        A = [k%2019]
        mi = min(A)
        new_list.append(mi)

print(min(new_list))

### FIXED CODE ###

import sys
L, R = map(int,input().split())

new_list = []
for i in range(L,R):
    for j in range(i+1, R+1):
        new_list.append((i*j)%2019)
        
        if (i*j)%2019 == 0:
            print(0)
            sys.exit()
print(min(new_list))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
mod = int(1e9 + 7)
re = {}
ans = 0
for i in range(n):
    for j in range(i+1,n):
        ans += a[i]*a[j]
        ans %= mod

print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
mod = int(1e9 + 7)
ans, x = 0, 0
for i in range(n):
    ans += a[i]*x
    x += a[i]
print(ans%mod)
### BUGGY CODE ###

N = int(input())

arr = [i+1 for i in range(N)]

print(sum(arr)-arr[-1])

### FIXED CODE ###

N = int(input())

if N == 1:
    print(0)
else:
    print((1+(N-1))*(N-1)//2)
### BUGGY CODE ###

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


def comb(n, r):
    if n < r or r < 0:
        return 0
    nume = 1
    deno = 1
    for i in range(1, r + 1):
        nume = (nume * (n - i + 1)) % P
        deno = (deno * i) % P
    deno_inv = pow(deno, P-2, P)
    return nume*deno_inv


for i in range(2, 2 * K + 1):
    ans = 0
    n_pair = min((i - 1) // 2, (2 * K - i + 1) // 2)
    out_pair = max(0, K-i+1, i-K-1)
    for j in range(n_pair+1):
        not_use = comb(n_pair, j)
        which_use = pow(2, n_pair - j, P)
        dice_cnt = comb(N - 1 + out_pair, n_pair - j - 1 + out_pair)
        if i % 2 == 0:
            dice_cnt = (dice_cnt + comb(N - 1 + out_pair - 1, n_pair - j - 1 + out_pair)) % P
        tmp = (not_use * which_use) % P
        tmp = (tmp * dice_cnt) % P
        ans = (ans + tmp) % P
        n_pair = min((i - 1) // 2, (2 * K - i + 1) // 2)
    print(ans)


### FIXED CODE ###

import sys

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


kaizyo = [0]
kaizyo_inv = [0]
tmp = 1
for i in range(1, N+K):
    tmp = (tmp*i) % P
    kaizyo.append(tmp)
    kaizyo_inv.append(pow(tmp, P - 2, P))


def comb(n, r):
    if n < r or r < 0:
        return 0
    elif n == r or r == 0:
        return 1
    else:
        return kaizyo[n] * kaizyo_inv[r] * kaizyo_inv[n - r]


inv_2 = pow(2, P - 2, P)
anss = ''
for i in range(2, 2 * K + 1):
    ans = 0
    n_pair = min((i - 1) // 2, (2 * K - i + 1) // 2)
    out_pair = max(0, K - i + 1, i - K - 1)
    which_use = pow(2, n_pair+1, P)
    for j in range(n_pair + 1):
        if n_pair - j > N:
            which_use = (which_use * inv_2) % P
            continue
        not_use = comb(n_pair, j)
        which_use = (which_use * inv_2) % P
        dice_cnt = comb(N - 1 + out_pair, n_pair - j - 1 + out_pair)
        if i % 2 == 0:
            dice_cnt = (dice_cnt + comb(N - 2 + out_pair,
                                        n_pair - j - 1 + out_pair)) % P
        tmp = (not_use * which_use) % P
        tmp = (tmp * dice_cnt) % P
        ans = (ans + tmp) % P
    anss += str(ans) + '\n'
print(anss.rstrip())
### BUGGY CODE ###

#!/usr/bin/env python3

x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ab = []
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse=True)

ab = ab[:k]

abc = []
for i in ab:
    for j in c:
        abc.append(i+j)
abc.sort(reverse=True)

for i in range(k):
    print(abc[i])


### FIXED CODE ###

#!/usr/bin/env python3

x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

# ab = []
# for i in a:
#     for j in b:
#         ab.append(i+j)
# ab.sort(reverse=True)

# ab = ab[:k]

# abc = []
# for i in ab:
#     for j in c:
#         abc.append(i+j)
# abc.sort(reverse=True)

# for i in range(k):
#     print(abc[i])

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

a_max = min(k, len(a))
b_max = min(k, len(b))
c_max = min(k, len(c))

abc = []
for i in range(1, k+1):
    if i > len(a):
        break
    for j in range(1, k//i+1):
        if j > len(b):
            break
        for l in range(1, k//(i*j)+1):
            if l > len(c):
                break
            # print(i, j, l)
            abc.append(a[i-1]+b[j-1]+c[l-1])

# print(abc)
# print(k)
abc.sort(reverse=True)
for i in range(k):
    print(abc[i])
### BUGGY CODE ###

N, D, A = map(int, input().split())
monster = []
for k in range(N):
  monster.append(list(map(int, input().split())))
monster.sort(key = lambda x: x[0])
ans = 0
k = 0
while k < len(monster):
  if monster[k][1] > 0:
    nowx = monster[k][0]
    damage = ((monster[k][1]-0.1)//A)*A + A
    ans += int((monster[k][1]-0.1)//A + 1)
    j = 0 + k
    nextk = N
    while(j +1 < len(monster)):
      j += 1
      if monster[j][0] <= nowx + 2*D:
        monster[j][1] -= damage
        if monster[j][1] > 0:
          nextk = min(j, nextk)
          continue
      else:
        nextk = min(nextk, j)
        break
    k = nextk

print(ans)

### FIXED CODE ###

N, D, A = map(int, input().split())
monster = []
for k in range(N):
  monster.append(list(map(int, input().split())))
monster.sort(key = lambda x: x[0])
for k in range(N):
  monster[k][1] = int((monster[k][1]-0.1)//A + 1)
ans = 0
"""
k = 0
while k < len(monster):
  if monster[k][1] > 0:
    nowx = monster[k][0]
    damage = monster[k][1]
    ans += monster[k][1]
    j = 0 + k
    nextk = N
    while(j +1 < len(monster)):
      j += 1
      if monster[j][0] <= nowx + 2*D:
        monster[j][1] -= damage
        if monster[j][1] > 0:
          nextk = min(j, nextk)
          continue
      else:
        nextk = min(nextk, j)
        break
    k = nextk
"""
final = monster[-1][0]
ruiseki = 0
minuslist = []
j = 0
for k in range(N):
  while (j < len(minuslist)):
    if monster[k][0] >= minuslist[j][0]:
      ruiseki -= minuslist[j][1]
      j += 1
    else:
      break
  if ruiseki < monster[k][1]:
    ans += monster[k][1] - ruiseki
    if monster[k][0] + 2*D +1 <= final:
      minuslist.append([monster[k][0]+2*D+1, monster[k][1] - ruiseki])
    ruiseki = monster[k][1]


print(ans)
### BUGGY CODE ###

# import sys 
# import os
# path = os.path.join(os.getcwd(),'input.txt')
# input = open(path).readline

import numpy as np
S = input()
cand = np.zeros(2019,dtype=int)
ans = 0
rem = 0
for i,s in enumerate(S[::-1]):
    rem += int(s)*(10**i)
    rem %= 2019
    cand[rem] +=1
ans = cand[0]
cand = cand[cand>1]
for c in cand:
    ans += c*(c-1)/2
print(int(ans))

### FIXED CODE ###

# import sys 
# import os
# path = os.path.join(os.getcwd(),'input.txt')
# input = open(path).readline

import numpy as np
S = input()
cand = np.zeros(2019,dtype=int)
rem = 0
order = 1
mod = 2019
for s in S[::-1]:
    rem += (int(s)*order)%mod
    rem %= mod
    cand[rem] +=1
    order *= 10
    order %=mod
ans = cand[0]
cand = cand[cand>1]
for c in cand:
    ans += c*(c-1)/2
print(int(ans))
### BUGGY CODE ###

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

cm = N
if N % K == 0:
    print(0)
    exit()
while True:
    cm = min(cm, abs(N - K))
    if cm >= N:
        break
    N = cm

print(cm)


### FIXED CODE ###

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

cm = N
k = N % K
if k == 0:
    print(0)
    exit()
print(min(abs(k-K), N))
### BUGGY CODE ###

import itertools

n=int(input())
a=list(map(int, input().split())) 
ans = 0
n = range(n)

for c in itertools.combinations(n, 2):
    #print(c)
    if c[1]-c[0] == a[c[0]]+a[c[1]]:
        ans += 1

print(ans)

### FIXED CODE ###

import collections
n=int(input())
a=list(map(int, input().split())) 
ans = 0
ru = []

for i in range(n):
    ru.append(int(i + 1 + a[i]))

c = collections.Counter(ru)
#print(c)

for i in range(n):
    tmp = i + 1 - a[i]
    ans += c[tmp]

print(ans)
### BUGGY CODE ###

#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def main():
#    h,w,a,b = map(int, input().split())
    x,y = map(int,input().split())
    a=max(x,y)
    b=min(x,y)

    t=a//2
    if b<t:
       ans=0
    elif (b-t)%3==0 and a%2==0:
       aa=a//2
       bb=(b-t)//3*2
       aa-=(b-t)//3
       ans=1
       for i in range(bb):
           ans*=(aa+bb-i)%MOD

       for i in range(bb):
           ans//=(bb-i)%MOD

 #      ans=cmb(aa+bb,bb)

    elif (b-t+1)%3==0 and a%2!=0:
       aa=a//2
       bb=(b-t)//3*2+1
       aa -= (b - t) // 3
       ans=1
       for i in range(bb):
           ans *= (aa+bb - i)%MOD

       for i in range(bb):
           ans //= (bb - i)%MOD

    else:
        ans=0


#    print(ans)
    print(ans%(10**9+7))
if __name__ == "__main__":
    main()

### FIXED CODE ###

#import sys

#input = sys.stdin.readline
import math
import itertools
#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def main():
#    h,w,a,b = map(int, input().split())
    x,y = map(int,input().split())
    a=max(x,y)
    b=min(x,y)

    t=a//2
    if b<t:
       ans=0
    elif (b-t)%3==0 and a%2==0:
       aa=a//2
       bb=(b-t)//3*2
       aa-=(b-t)//3
       ans=1
       ans=cmb(aa+bb,bb)

    elif (b-t+1)%3==0 and a%2!=0:
       aa=a//2
       bb=(b-t)//3*2+1
       aa -= (b - t) // 3
       ans=1
       ans=cmb(aa+bb,bb)

    else:
        ans=0


#    print(ans)
    print(ans%(10**9+7))
if __name__ == "__main__":
    main()
### BUGGY CODE ###

n = int(input())
a = []
for _ in range(n):
    A = int(input())
    a.append(A)
    
s = sorted(a)
for i in range(n):
    if max(a) == a[i]:
        print(s[-2])
    else:
        print(max(a))

### FIXED CODE ###

n = int(input())
a = []
for _ in range(n):
    A = int(input())
    a.append(A)
    
s = sorted(a)
for i in range(n):
    if a[i] == s[-1]:
        print(s[-2])
    else:
        print(s[-1])
### BUGGY CODE ###

from collections import deque
h, w = map(int, input().split())
maze = []
for _ in range(h):
    maze.append(list(input()))

def clear_maze(sx, sy, gx, gy, maze):
    INF = float('infinity')
    field_x_length = len(maze)
    field_y_length = len(maze[0])
    distance = [[INF for i in range(field_y_length)] for j in range(field_x_length)]

    def bfs():
        queue = deque([(sx, sy)])
        distance[sx][sy] = 0
        dx = [1, 0, -1, 0]
        dy = [0, 1, 0, -1]
        while queue:
            x, y = queue.pop()
            if x == gx and y == gy:
                break
            for i in range(0, 4):
                nx, ny = x + dx[i], y + dy[i]
                if (0 <= nx < field_x_length) and (0 <= ny < field_y_length):
                    if maze[nx][ny] != '#' and distance[nx][ny] == INF:
                        queue.appendleft((nx, ny))
                        distance[nx][ny] = distance[x][y] + 1
        return distance[gx][gy]
    return bfs()


pairs = []
for i in range(h):
    for j in range(w):
        if maze[i][j] == '.':
            pairs.append([i, j])

MAX = 0
s = set()
for i in range(len(pairs)):
    sx, sy = pairs[i]
    for j in range(len(pairs)):
        gx, gy = pairs[j]
        if i == j or (sx, sy, gx, gy) in s or (gx, gy, sx, sy) in s:
            continue
        s.add((sx, sy, gx, gy))
        s.add((gx, gy, sx, sy))
        r = clear_maze(sx, sy, gx, gy, maze)
        if r == float('infinity'):
            continue
        MAX = max(MAX, r)
print(MAX)

### FIXED CODE ###

from collections import deque
h, w = map(int, input().split())
maze = []
for _ in range(h):
    maze.append(list(input()))

def clear_maze(sx, sy, maze):
    INF = -float('infinity')
    field_x_length = len(maze)
    field_y_length = len(maze[0])
    distance = [[INF for i in range(field_y_length)] for j in range(field_x_length)]

    queue = deque([(sx, sy)])
    distance[sx][sy] = 0
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    while queue:
        x, y = queue.pop()
        # if x == gx and y == gy:
        #     break
        for i in range(0, 4):
            nx, ny = x + dx[i], y + dy[i]
            if (0 <= nx < field_x_length) and (0 <= ny < field_y_length):
                if maze[nx][ny] != '#' and distance[nx][ny] == INF:
                    queue.appendleft((nx, ny))
                    distance[nx][ny] = distance[x][y] + 1
    MAX = 0
    for row in range(field_x_length):
        for col in range(field_y_length):
            MAX = max(MAX, distance[row][col])
    return MAX
    # return distance[gx][gy]

pairs = []
for i in range(h):
    for j in range(w):
        if maze[i][j] == '.':
            pairs.append([i, j])

MAX = 0
for sx, sy in pairs:
    r = clear_maze(sx, sy, maze)
    MAX = max(MAX, r)
print(MAX)
### BUGGY CODE ###

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

ans = 1

while n != 1:
    ans += 1
    n = n//k
    
print(ans)

### FIXED CODE ###

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

ans = 1

while n >= k:
    ans += 1
    n = n//k
    
print(ans)
### BUGGY CODE ###

import numpy as np

n = int(input())
x = np.array(list(map(int, input().split(" "))))

sorted_x = sorted(x)
sorted_ind = list(np.argsort(x))
half_n = int(n / 2)

# print(x)
# print(half_n)
# print(sorted_ind)
# print(sorted_x)

for i in range(n):
    # print("==========")
    ind = sorted_ind.index(i)
    # print("ind: {}".format(ind))
    if ind <= half_n - 1:
        print(sorted_x[half_n - 1 + 1])
    else:
        print(sorted_x[half_n - 1])


### FIXED CODE ###

n = int(input())
x = list(map(int, input().split()))

sorted_x = sorted(x)

median_1 = sorted_x[n//2-1]
median_2 = sorted_x[n//2]

for i in range(n):
    if x[i] <= median_1:
        print(median_2)
    else:
        print(median_1)
### BUGGY CODE ###

n = int(input())

l = [0] * n
for i in range(n):
    l[i] = input()

k = set(l)
m = 0
ans = []

for i in k:
    cnt = l.count(i)
    if cnt > m:
        m = cnt
        del ans[:]
        ans.append(i)
    elif cnt == m:
        ans.append(i)

ans.sort()

print(*ans, sep="\n", end="")

### FIXED CODE ###

n = int(input())

words = {}

for i in range(n):
    key = input()
    if key not in words:
        words[key] = 0
    words[key] += 1

l = []
th = max(words.values())

for i,j in words.items():
    if th == j:
        l.append(i)

l.sort()

print(*l, sep="\n", end="")
### BUGGY CODE ###


class SegTree(object):
    """docstring for SegTree."""
    def __init__(self, l, _n):
        n = 1
        while n<_n:
            n *= 2
        self.n = n
        self.dat = [set() for _ in range(2*n)]
        for i in range(_n):
            self.dat[i+n-1].add(l[i])
        self.init(0)

    def init(self, i):
        if i>=self.n-1:
            return self.dat[i]
        self.dat[i] = self.init(self.left(i)) | self.init(self.right(i))
        return self.dat[i]

    def par(self, i):
        return (i-1)//2

    def left(self, i):
        return 2*i+1

    def right(self, i):
        return 2*i+2

    def update(self, i, x):
        i += self.n-1
        self.dat[i] = x
        while i>0:
            i = self.par(i)
            self.dat[i] = self.dat[self.left(i)] | self.dat[self.right(i)]

    def q(self,a,b,k,l,r):
        if r<=a or b<=l:
            return set()
        if a<=l and r<=b:
            return self.dat[k]
        return self.q(a,b,self.left(k),l,(l+r)//2) | self.q(a,b,self.right(k),(l+r)//2,r)

    def query(self,a,b):
        return self.q(a,b,0,0,self.n)

n = int(input())
s = list(input())
q = int(input())
ql = [input().split() for _ in range(q)]

seg = SegTree(s,n)

for i in range(q):
    if ql[i][0]=="1":
        seg.update(int(ql[i][1])-1, set([ql[i][2]]))
    else:
        r = seg.query(int(ql[i][1])-1, int(ql[i][2]))
        print(len(r))

### FIXED CODE ###


class SegTree(object):
    """docstring for SegTree."""
    def __init__(self, l, _n):
        n = 1
        while n<_n:
            n *= 2
        self.n = n
        self.dat = [0 for _ in range(2*n)]
        for i in range(_n):
            self.dat[i+n-1] |= 1<<l[i]
        self.init(0)

    def init(self, i):
        if i>=self.n-1:
            return self.dat[i]
        self.dat[i] = self.init(self.left(i)) | self.init(self.right(i))
        return self.dat[i]

    def par(self, i):
        return (i-1)//2

    def left(self, i):
        return 2*i+1

    def right(self, i):
        return 2*i+2

    def update(self, i, x):
        i += self.n-1
        self.dat[i] = 1<<x
        while i>0:
            i = self.par(i)
            self.dat[i] = self.dat[self.left(i)] | self.dat[self.right(i)]

    def q(self,a,b,k,l,r):
        if r<=a or b<=l:
            return 0
        if a<=l and r<=b:
            return self.dat[k]
        return self.q(a,b,self.left(k),l,(l+r)//2) | self.q(a,b,self.right(k),(l+r)//2,r)

    def query(self,a,b):
        return self.q(a,b,0,0,self.n)

n = int(input())
s = [ord(c)-ord("a") for c in input()]
q = int(input())
ql = [input().split() for _ in range(q)]

seg = SegTree(s,n)

for i in range(q):
    if ql[i][0]=="1":
        seg.update(int(ql[i][1])-1, ord(ql[i][2])-ord("a"))
    else:
        r = seg.query(int(ql[i][1])-1, int(ql[i][2]))
        print(bin(r).count("1"))
### BUGGY CODE ###

k, s = map(int, input().split())

l = set()
for i in range(k+1):
    for j in range(k+1):
        if i+j+k >= s and s-i-j >= 0:
            l.add((i, j, s-i-j))
        else:
            continue

print(len(l))

### FIXED CODE ###

k, s = map(int, input().split())

count = 0
for i in range(k+1):
    for j in range(k+1):
        if i+j+k >= s and s-i-j >= 0:
            count += 1
        else:
            continue

print(count)
### BUGGY CODE ###

N,M = map(int, input().split())
money = list(map(int, input().split()))
 
for i in range(M):
  money[money.index(max(money))]//=2
 
print(sum(money))

### FIXED CODE ###

import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[-int(i) for i in a]

heapq.heapify(b)

for i in range(m):
    x=-heapq.heappop(b)//2
    heapq.heappush(b,-x)

print(-sum(b))
### BUGGY CODE ###

input()
s=input().split()
a=[]
for i in s:
 a.append(int(i))
a.sort()
input()
s=input().split()
b=[]
for i in s:
 b.append(int(i))
b.sort()
while len(a)>0:
    if a[0]==b[0]:
        del(a[0])
        del(b[0])
        if len(b)==0:
            break
    elif a[0]<b[0]:
        del(a[0])
    else:
        a=[]
if len(b)==0:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

lena=int(input())
s=input().split()
a=[]
for i in s:
 a.append(int(i))
a.sort()
lenb=int(input())
s=input().split()
b=[]
for i in s:
 b.append(int(i))
b.sort()
i=0
j=0
while i<lena:
    if a[i]==b[j]:
        i+=1
        j+=1
        if j==lenb:
            break
    elif a[i]<b[j]:
        i+=1
    else:
        break
if j==lenb:
    print("YES")
else:
    print("NO")
### BUGGY CODE ###

import heapq
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1

dist = []
for i in range(n):
    dist.append([110110] * n)

def dijkstra(s):
    h = []
    heapq.heappush(h, (0, s))
    dist[s][s] = 0
    while len(h) != 0:
        pair = heapq.heappop(h)
        now = pair[1]
        dis = pair[0]
        if dis < dist[s][now]:
            continue

        if now != 0:
            if dist[s][now] + 1 < dist[s][now-1]:
                dist[s][now-1] = dist[s][now] + 1
                heapq.heappush(h, (dist[s][now-1], now-1))
        if now != n-1:
            if dist[s][now] + 1 < dist[s][now+1]:
                dist[s][now+1] = dist[s][now] + 1
                heapq.heappush(h, (dist[s][now+1], now+1))
        if now == x:
            if dist[s][now] + 1 < dist[s][y]:
                dist[s][y] = dist[s][now] + 1
                heapq.heappush(h, (dist[s][y], y))
        if now == y:
            if dist[s][now] + 1 < dist[s][x]:
                dist[s][x] = dist[s][now] + 1
                heapq.heappush(h, (dist[s][x], x))

cnt = [0] * n

for i in range(n):
    dijkstra(i)
for i in range(n):
    for j in range(n):
        cnt[dist[i][j]] += 1
for i in range(1, n):
    print(cnt[i] // 2)


### FIXED CODE ###

n, x, y = list(map(int, input().split()))
x -= 1
y -= 1

cnt = [0] * n

dist = []
for i in range(n):
    dist.append([-1] * n)
for i in range(n):
    dist[i][x] = abs(i-x)
    dist[i][y] = abs(i-y)
    dist[x][i] = abs(i-x)
    dist[y][i] = abs(i-y)

for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        dis = min(j - i, dist[j][y] + 1 + dist[i][x], dist[j][x] + 1 + dist[i][y])
        cnt[dis] += 1
for i in range(1, n):
    print(cnt[i])
### BUGGY CODE ###

A,B,M=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)

### FIXED CODE ###

A,B,M=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)