peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
s = input()
flg1 = s[0] == "A"
flg2 = s[2:-1].count("C") == 1
s = s.replace("A", "")
s = s.replace("C", "")
flg3 = s.islower()
print(["WA", "AC"][flg1 and flg2 and flg3])
# Judge status: Accepted
n = int(input())
s = [input() for i in range(n)]
from collections import Counter
b = Counter(s)
print('AC x '+str(b['AC']))
print('WA x '+str(b['WA']))
print('TLE x '+str(b['TLE']))
print('RE x '+str(b['RE']))
# Judge status: Wrong Answer
def powmod(a,n,mod):
    ans = 1
    while n > 0:
        if n & 1:  # nの2進数表示の末尾が1か
            ans = ans * a % mod
        a = a ** 2 % mod  # aを2乗する
        n >>= 1  # nを2で割る
        #print(ans,a,n)
    return ans

#2分累乗法　ばらして余りとってかけ算
N=int(input())
m=powmod(10,N,1000000007)-powmod(9,N,1000000007)-powmod(9,N,1000000007)+powmod(8,N,1000000007)
print(m)
# Judge status: Accepted
a, b = map(int, input().split())
if a <= 8 and b <= 8:
    print("Yay!")
else:
    print(":(")
# Judge status: Accepted
a,b = map(int, input().split())
if a>0 and b>0:
    print("Positive")
elif a<=0 and b>=0:
    print("Zero")
elif a<0 and b<0:
    if (b-a+1)%2 == 0:
        print("Positive")
    elif(b-a+1)%2 == 1:
        print("Negative")
# Judge status: Wrong Answer
S=input()
SR=S[::-1]
ans=0

for i in range(len(S)):
    if S[i] != SR[i]:
        ans = ans + 1

print(ans-1)
# Judge status: Wrong Answer
s=list(input())
lowercase = 'abcdefghijklmnopqrstuvwxyz'
count=0
for moji in lowercase:
  count+=1
  if count==len(s):
    print('None')
    break
  if moji not in s:
    print(moji)
    break
# Judge status: Accepted
N,X,Y = map(int,input().split())
X-=1;Y-=1
ans = [0 for _ in range(N-1)]
for i in range(N):
  for j in range(i+1,N):
    direct = j-i
    shortcut = abs(X-i)+1+abs(Y-j)
    shortest = min(direct,shortcut)
    ans[shortest-1] += 1
print(*ans,sep="\n")
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

suma = sum(a)
sumb = sum(b)
sousa = sumb-suma

import math
plus1=0
plus2=0
for i in range(n):
    if a[i] < b[i]:
        plus2+=math.ceil((b[i]-a[i])/2)
    elif a[i] > b[i]:
        plus1+=a[i]-b[i]

if plus1<=sousa and plus2<=sousa:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n, k = map(int, input().split())
d = [ int(x) for x in input().split() ]

def is_ok(x):
    while x != 0:
        if x % 10 in d:
            return False
        x //= 10
    return True

money = n
while True:
    if is_ok(n):
        print(n)
        break
    n += 1
# Judge status: Accepted
string=input()
s=set(list(string))

full=set(list("abcdefghijklmnopqrstuvwxyz"))

tmp=full-s
if len(tmp)==0:
  print("None")
  exit()
print(min(tmp))
# Judge status: Accepted
a=int(input())
b=int(input())
print(6-a-b)
# Judge status: Accepted
import bisect

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

A.sort()
B.sort()
C.sort()

ans = 0

for b in B:
    a_count = bisect.bisect_left(A, b)
    c_count = N - bisect.bisect_right(C, b)
    ans += a_count * c_count
print(ans)
# Judge status: Wrong Answer
N, K = map(int, input().split())
S = input()
s = S[K - 1]
S = list(S)
S[K - 1] = str.lower(s)
S = str(S)

print(S)
# Judge status: Accepted
from collections import Counter

def combination(n, r): #nCrを求める
    if n - r > r:
        r = n - r
    tmp = 1
    for i in range(n - r + 1, n + 1):
        tmp *= i
    for i in range(1, r + 1):
        tmp //= i
    return tmp

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

B = [A[i] % 2 for i in range(N)]

C = Counter(B)

odd = C[1]
even = C[0]

ans = 0
for i in range(P, odd + 1, 2):
    tmp = combination(odd, i)
    ans += tmp

ans *= pow(2, even)
print (ans)
# Judge status: Accepted
import queue

K = int(input())

Q = queue.Queue()
for i in range(1, 10):
    Q.put(i)

for i in range(K-1):
    x = Q.get()
    if x%10 != 0:
        Q.put(10*x+x%10-1)
    Q.put(10*x+x%10)
    if x%10 != 9:
        Q.put(10*x+x%10+1)
print(Q.get())
# Judge status: Accepted
n = (int)(input())
s = sorted([sorted(list(input())) for i in range(n)])
 
ans = 0
temp = 1
for i in range(n - 1):
  if s[i] == s[i + 1]:
    temp += 1
  else:
    if temp != 1:
      ans += temp * (temp - 1) // 2
      temp = 1
else:
  if temp != 1:
    ans += temp * (temp - 1) // 2
    temp = 1
print(ans)
# Judge status: Accepted
A,B = map(int,input().split())

if A<=9 and B<=9:
  print(A*B)
else:
  print(-1)
# Judge status: Accepted
import math

x = int(input())
x = abs(x)

# sum = sec(sec+1)/2
a = math.ceil((2 * x) ** (0.5))
s = a * (a+1) // 2

while s >= x:
    a -= 1
    s = a * (a+1) // 2

print(a+1)
# Judge status: Accepted
import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)
# Judge status: Wrong Answer
n = int(input())
ans = []
while n != 0:
    c = n // 2 + 1
    ans.append(c)
    n -= c

print("\n".join(list(map(str, ans))))
# Judge status: Accepted
N,M=map(int,input().split())
ac=[False]*N
wa=[0]*N
for _ in range(M):
  p,S=input().split()
  p=int(p)-1
  if S=='AC':
    ac[p]=True
  else:
    if not ac[p]:
      wa[p]+=1
a=0
b=0
for i in range(N):
  if ac[i]:
    a+=1
    b+=wa[i]
print(*[a,b])
# Judge status: Accepted
K = int(input())
L = list(range(1, K))
n = (K // 2)
if K % 2 == 0:
    print(n**2)
else:
    print(n * (n + 1))
# Judge status: Accepted
n = int(input())
S = []
ans = ''

for i in range(n):
    S.append(str(input()))

data1 = []
data2 = []

for i in range(len(S[0])):
    if not S[0][i] in data1:
        data1.append(S[0][i])
        data2.append(1)
    else:
        data2[data1.index(S[0][i])] += 1

for i in range(1, n):
    for j in range(len(data1)):
        data2[j] = min(data2[j], S[i].count(data1[j]))

for i in range(len(data1)):
    ans += data1[i] * data2[i]

print(''.join(sorted(ans)))
# Judge status: Accepted
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n = INT()
a = LIST()
l1 = [i+1+a[i] for i in range(n)]
l2 = [i+1-a[i] for i in range(n)]
c1 = Counter(l1)
c2 = Counter(l2)
res = 0
inter = set(l1) & set(l2)
for value in inter:
    res += c1[value]*c2[value]

print(res)
# Judge status: Wrong Answer
import math
A,H= map(int, input().split())
print(math.ceil(H/A))
# Judge status: Accepted
s = input()

for bit in range(1<<3):
  ans=""
  for i in range(3):
    if bit & (1<<i):
      ans+="+"
    else:
      ans+="-"
  ans=s[0]+ans[0]+s[1]+ans[1]+s[2]+ans[2]+s[3]
  if eval(ans)==7:
    print(ans+"=7")
    break
# Judge status: Accepted
from collections import deque
def main():
	N,M,*AB=map(int,open(0).read().split())
	to=[[] for _ in range(N)]
	for a,b in zip(*[iter(AB)]*2):
		to[a-1].append(b-1)
		to[b-1].append(a-1)
	q=deque([0])
	r=[None]*N
	while q:
		x=q.popleft()
		for i in to[x]:
			if not r[i]:
				q.append(i)
				r[i]=x+1
	print("Yes",*r[1:],sep="\n")
if __name__=='__main__':
	main()
# Judge status: Wrong Answer
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
a=lnii()

c=Counter(a)
a_max=max(a)

ans=0
for i in range(a_max):
  t_ans=c[i-1]+c[i]+c[i+1]
  ans=max(ans,t_ans)

print(ans)
# Judge status: Accepted
n, m = map(int, input().split())

p = set()
q = set()

for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        p.add(b)
    elif b == n:
        q.add(a)
else:
    if p & q:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
# Judge status: Wrong Answer
A, B, C = map(int, input().split())
print(C - (A-B))
# Judge status: Accepted
n = int(input())
al = list(map(int,input().split()))

now = 1
cnt = 0
for a in al:
    if a == now:
        cnt += 1
        now += 1
if cnt == 0:
    print(-1)
else:
    print(n-cnt)
# Judge status: Wrong Answer
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        print(i)
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table


n = int(input())
ans = 0
div_list = num_divisors_table(n)

for i in range(1, n+1):
    ans += i * div_list[i]

print(ans)
# Judge status: Accepted
# coding: utf-8
import numpy as np

n = int(input())

dp = [np.inf for _ in range(n+10)]
dp[0] = 0

for i in range(1, n+1):
    dp[i] = i
    pow6 = 1
    while pow6 <= i:
        dp[i] = min(dp[i], dp[i-pow6]+1)
        pow6 *= 6
    pow9 = 1
    while pow9 <= i:
        dp[i] = min(dp[i], dp[i-pow9]+1)
        pow9 *= 9
    
print(dp[n])
# Judge status: Wrong Answer
a,b,t = map(int,input().split())

for i in range(1,20):
  if i*(i+1)/2 >t+0.5:
    print(b*(i-1))
    break
# Judge status: Accepted
n = int(input())
a = int(input())

if n % 500 <= a:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
N = int(input())

mod = 10**9+7
if N == 1:
  result = 0
else:
  result = (10**(N-2) * 2) % mod

print(result)
# Judge status: Wrong Answer
s = int(input())
lst = [0,0,1]
num = 10**9 + 7
if s>= 4:
  for i in range(4,s+1):
    ans = (lst[i-2] + lst[i-4])%num
    lst.append(ans)
print(lst[-1]%num)
# Judge status: Accepted
list = []
N = int(input())
for i in range(N):
  S, P = map(str, input().split())
  list.append((i+1, S, int(P)))
list = sorted(list, key=lambda x:(x[1], -x[2]))
 
for l in list:
  print(l[0])
# Judge status: Wrong Answer
a = list(map(int, input().split()))
if(a[0]>a[1]):
  for _ in range(a[0]):
    print(a[0], end = "")
elif(a[0]<a[1]):
  for _ in range(a[0]):
    print(a[1], end = "") 
else:
  for _ in range(a[0]):
    print(a[0], end = "")
# Judge status: Wrong Answer
from collections import Counter


MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
cnt_D = Counter(D)
if cnt_D.get(0, 0) != 1:
    print(0)
else:
    prev = cnt_D.get(1, 0)
    ans = 1
    for i in range(2, max(D) + 1):
        if prev == 0:
            ans = 0
            break
        v = cnt_D.get(i, 0)
        ans *= pow(prev, v, MOD)
        ans %= MOD
        prev = v
    print(ans)
# Judge status: Accepted
n,k = map(int,input().split())
array = []
for i in range(n):
  array.append(int(input()))
  
array.sort()

min = 1000000000
for i in range(n-k+1):
  dif = array[i+k-1] - array[i]
  if min>dif:
    min = dif
    
print(min)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

m = 0
for a in A:
    m ^= a

ans = []
for a in A:
    ans.append(a ^ m)

print(*ans)
# Judge status: Accepted
w,h = map(int, input().split())
x = w*h

if h !=1 and w != 1:
    print((h*w+1)//2)
else:
    print(1)
# Judge status: Accepted
if __name__ == '__main__':
	S = input()
	T = input()

	set_S = set(S)
	set_T = set(T)
	if len(set_S) != len(set_T):
		print("No")
		exit()

	dic = dict()

	flg = True
	for x,y in zip(S,T):
		if x not in dic:
			dic[x] = y
		else:
			if dic[x] != y:
				flg = False
				break
	
	if flg :
		print("Yes")
	else:
		print("No")
# Judge status: Accepted
import sys
input = sys.stdin.readline
N, M = map(int, input().split())

ret = 0
if N >= 2:
  ret += N * (N-1) // 2
if M >= 2:
  ret += M * (M-1) // 2
print(ret)
# Judge status: Accepted
N = int(input())
print(int((1+N) * N/2))
# Judge status: Wrong Answer
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

a, b = 0, 0
for i, _p in enumerate(itertools.permutations(list(range(1, n+1)))):
    if p == _p:
        a = i
    elif q == _p:
        b = i

print(abs(a-b))
# Judge status: Wrong Answer
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    flag = True
    s = input()
    c = Counter(s)
    values, counts = zip(*c.most_common())
    for i in counts:
        if (i%2 != 0):
            flag = False
    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()
# Judge status: Accepted
S=input()
print("Good" if S[0]!=S[1] and S[1]!=S[2] and S[2]!=S[3] else "Bad")
# Judge status: Accepted
N, K = map(int, input().split())
n_1 = N - (K * (N // K))
n_2 = abs(n_1 - K)
print(min(n_1, n_2))
# Judge status: Accepted
a, b, k = map(int, input().split())

if a > k:
    print(a-k, b)
elif a + b > k:
    print(0, a + b - k)
else:
    print(0, 0)
# Judge status: Wrong Answer
n = int(input())

if n % 9 or n < 9:
    print('No')
else:
    print('Yes')
# Judge status: Wrong Answer


def solution(h):
    n = len(h)
    INF = float('inf')
    dp = [INF]*n
    dp[0] = 0
    for i in range(n):
        for j in range(i+1,i+3):
            if j < n:
                dp[j] = min(dp[j] , dp[i]+abs(h[i]-h[j]) )
    print(*dp)
    return dp[n-1]

N = int(input())
h = list(map(int,input().split()))
res = solution(h)
print(res,end="")
# Judge status: Accepted
from math import sqrt


def route(a, b):
    return(sqrt((p[a-1][0]-p[b-1][0])**2+(p[a-1][1]-p[b-1][1])**2))


n = int(input())
p = list()
for i in range(n):
    p.append(tuple(map(int, input().split())))

sum = int()
cnt = int()
for i in range(1, n):
    for j in range(i+1, n+1):
        #print(i, j)
        sum+=route(i,j)
        cnt+=1

sum*=n-1
print(sum/cnt)
# Judge status: Accepted
n = int(input())
ans = [0 for _ in range(10001)]
for i in range(1,100):
    for j in range(1,100):
        for k in range(1,100):
            v = i**2 + j**2 + k**2 + i*j + j*k + k*i
            if v < 10001:
                ans[v] += 1

for i in range(n):
    print(ans[i+1])
# Judge status: Wrong Answer
#ABC176 B
N = list(map(int,input()))
n = 0
for i in N:
  n += i

if n == 0:
  print('No')
elif n % 9 == 0:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
a,b = map(int, input().split())
print(b if a >= 13 else b // 2 if a >= 6 and a <= 12 else 0)
# Judge status: Accepted
n = int(input())
sum = 0
for i in range (n+1):
    if i%3==0 and i%5==0:
        continue
    elif i%3==0:
        continue
    elif i%5==0:
        continue
    else:
        sum += i
print(sum)
# Judge status: Wrong Answer
r=input().split()
H=int(r[0])
N=int(r[1])
data_pre=input().split()
data=[int(s) for s in data_pre]
if max(data)>=H:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
a= list(map(int, input().split()))

x = a[0]
y = a[1]

n = 2
if y == 1:
    print(0)
elif x >= y:
    print(1)
else:
    while ((x * n) - (n - 1)) < y:
        n += 1
    print(n)
# Judge status: Accepted
a,b,c,d = (int(i) for i in input().split())
if (abs(a-b)<=d and abs(b-c)<=d) or abs(a-c)<=d: print("Yes")
else: print("No")
# Judge status: Accepted
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

a, b = map(int,readline().split())
print(max(2 * a - 1, 2 * b - 1, a + b))
# Judge status: Accepted
x=int(input())
l=[0]*(x+1)

if x==1:
    print(1)
    exit()
    
for i in range(1,x):
    for j in range(2,1000):
        if i**j>x:
            break
        l[i**j]=1

for i in reversed(range(x+1)):
    if l[i]==1:
        print(i)
        exit()
# Judge status: Accepted
a,b,c=map(int,input().split())
if a<=c and c<=b:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
N, A, B = map(int, input().split())
S = input()
 
ok_count = 0
ok_fcount = 0
for i in range(N):
  if S[i] == 'a':
    if ok_count < A+B:
      print('Yes')
      ok_count +=1
      
    else:
      print('No')
      
  elif S[i] == 'b':
    if ok_count < A+B and ok_fcount <= B:
      print('Yes')
      ok_count+=1
      ok_fcount+=1
      
    else:
      print('No')
      
  else:
    print('No')
# Judge status: Wrong Answer
n=int(input())
A=[int(input()) for i in range(n)]
B=sorted(A)
for a in A:
    if a == B[-1]:
      print(B[-1])
    else:
        print(B[-2])
# Judge status: Wrong Answer
n=int(input())
s=input().strip()
R=s.count('R')
t=0
for i in range(R):
    if s[i]=='W':
        t=t+1
u=R-(n-R-t)
f=max(t,u)
if R==0 or R==n or t==R:
    f=0
print(f)
# Judge status: Accepted
n = int(input())

a = 0

for i in range(1,n+1):
    if i%3 and i%5:
        a += i

print(a)
# Judge status: Wrong Answer
n=int(input())
count=0
for i in range(n):
    d1,d2=list(map(int,input().split()))
    if d1==d2:
        count+=1
if count>=3:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
A=int(input())
B=int(input())
C=int(input())
X=int(input())
a=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (500*i + 100*j +50*k ==X):
                a+=1
print(a)
# Judge status: Wrong Answer
#input
a, B, c = map(int, input().split())
d, e, f = map(int, input().split())
h, i, j = map(int, input().split())
N = int(input())
b = [0] * N
for i in range(N):
    b[i] = int(input())

#output
if a and B and c in b:
    print("Yes")
elif d and e and f in b:
    print("Yes")
elif h and i and j in b:
    print("Yes")
elif a and d and h in b:
    print("Yes")
elif B and e and i in b:
    print("Yes")
elif c and f and j in b:
    print("Yes")
elif a and e and j in b:
    print("Yes")
elif c and e and h in b:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
x,y = map(int,input().split())

ans = 1
while x<y:
    x*=2
    ans+=1
    if x>y:
        ans-=1
        break
print(ans)
# Judge status: Accepted
n = int(input())

p = 1

for i in range(1, n+1):
    p = p*i%(10**9+7)
print(p)
# Judge status: Wrong Answer
n = int(input())
s = input()

cnt = 0

ans = s[1:].count('E')

for i in range(1,n):
    if s[i-1] == "W":
        cnt += 1
    if s[i] == "E":
        cnt -= 1
    
    ans = min(ans,cnt)

print(ans)
# Judge status: Wrong Answer
n = int(input())

ans = float("inf")  
for i in range(n+1):
    a = sum([int(i) for i in list(str(i))])
    b = sum([int(i) for i in list(str(n-i))])
    ans = min(a+b, ans)

print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for i in range(n):
  #左側
  left = min(a[i], b[i])
  ans += left

  a[i] -= left
  b[i] -= left

  #右側
  right = min(a[i + 1], b[i])
  ans += right
  a[i + 1] -= right
  b[i] -= right

print(ans)
# Judge status: Accepted
x,a,b=map(int,input().split())
if abs(a-x)<abs(b-x):
    print("A")
else:
    print("B")
# Judge status: Accepted
import math
A,B,H,M=map(int,input().split())
A_sin=A*math.sin(2*math.pi*(60*H+M)/720)
A_cou=A*math.cos(2*math.pi*(60*H+M)/720)
B_sin=B*math.sin(2*math.pi*(M/60))
B_cos=B*math.cos(2*math.pi*(M/60))
ans=math.sqrt((A_sin-B_sin)**2+(A_cou-B_cos)**2)
print(ans)
# Judge status: Accepted
a=int(input())
print(a+a**2+a**3)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

a.sort()

ans = 0
tmp = 10 ** 9

for i in a:
    if tmp > abs(i - a[n - 1] / 2):
        tmp = abs(i - a[n - 1] / 2)
        ans = i

print(a[n - 1], ans)
# Judge status: Accepted
n,p = map(int,input().split())
A = list(map(int,input().split()))

even = sum([a%2==0 for a in A])
odd = n - even

def nCr(n,r):
  ret = 1
  for i in range(r):
    ret *= n-i
    ret //= i+1  
  return ret
  
ans = 0
add = 2 ** even
for k in range(p,odd+1,2):  
  ans += nCr(odd,k) * add  
  
print(ans)
# Judge status: Accepted
from math import ceil
N,K=map(int,input().split())
_=[i for i in input().split()]
print(ceil((N-1)/(K-1)))
# Judge status: Accepted
s=input()
n=len(s)
count=0
a=(n-1)//2
b=(n+3)//2
for i in range(n//2):
  if s[i]!=s[-abs(i+1)]:
    count+=1
    
for i in range(a//2):
  if s[i]!=s[(a-1-i)]:
    count+=1

for i in range((n-b+1)//2):
  if s[-(i+1)]!=s[b-1+i]:
    count+=1

if count!=0:
  print('No')
else:
  print('Yes')
# Judge status: Wrong Answer
A,B,M = 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] = map(int,input().split())
ans = 10**10
ma = max(c)
#ind = c.index(ma)
am = min(a)
bm = min(b)
mae = am + bm #ここまで
#indxy = a[x[ind]-1] + b[y[ind]-1] - ma

for i in range(M):
  mai = a[x[i]-1] + b[y[i] -1] - c[i]
  if mai < ans:
    ans = mai
print(ans)
# Judge status: Wrong Answer
import sys
input=sys.stdin.buffer.readline
N=int(input())
tax=27/25
for i in range(1,N):
    money=int(i*tax)
    if money==N:
        print(money)
        exit(0)
print(":(")
# Judge status: Accepted
n=int(input())
s=input()
t=s.count('R')*s.count('G')*s.count('B')
for i in range(n):
  j=1
  while i+j*2<n:
    if s[i]!=s[i+j] and s[i+j]!=s[i+2*j] and s[i]!=s[i+2*j]:
      t-=1
    j+=1
print(t)
# Judge status: Accepted
s = input()

INF = float('inf')
dp = [[INF,INF] for _ in range(len(s)+1)]
dp[0][0]=0
dp[0][1]=1
for i in range(len(s)):
    dp[i+1][0] = min(dp[i][0]+int(s[i]), dp[i][1]+10-int(s[i]), dp[i][1]+int(s[i])+1)
    dp[i+1][1] = min(dp[i][0]+int(s[i])+1,dp[i][1]+10-int(s[i])-1)

print(dp[-1][0])
# Judge status: Wrong Answer
import sys
n=int(input())
a=n
b=n
if n%4==0 or n%7==0:
	print("Yes")
	sys.exit()	
for k in range(1,n,4):
	a-=k
	if a%7==0:
		print("Yes")
		sys.exit()
for d in range(1,n,7):
	b-=d
	if b%4==0:
		print("Yes")
		sys.exit()
print("No")
# Judge status: Accepted
N = int(input())
print(111*-(-N//111))
# Judge status: Wrong Answer
n = int(input())
a = []

for i in range(n):
  a.append(int(input()))

a.sort()

print(len(set(a)) - (len(a) - len(set(a))))
# Judge status: Accepted
H,N=[int(i)for i in input().split()]
A=[int(i)for i in input().split()]
print("Yes" if sum(sorted(A)[:N])>=H else "No")
# Judge status: Accepted
S = input()
N = len(S)

from collections import Counter

c = Counter(S)

items = sorted(c.items(), key=lambda x: x[1])

if N == 1:
    print('YES')
elif N == 2:
    if len(items) == 1:
        print('NO')
    else:
        print('YES')
else:
    if len(items) < 3:
        print('NO')
    else:
        min = items[0][1]
        max = items[-1][1]
        if max - min >= 2:
            print('NO')
        else:
            print('YES')
# Judge status: Accepted
n, k = map(int, input().split(" "))

keta = 1
sum = 0
while True:
    max = k**keta-1
    if max >= n:
        print(keta)
        break
    keta += 1
# Judge status: Accepted
a,b,c,k = map(int,input().split())

ans = 0
if a<k:
    ans+=a
    k-=a
else:
    ans+=k
    k = 0

if b<k:
    k-=b
else:
    k = 0

if c<k:
    ans-=c
    k-=c
else:
    ans-=k
    k = 0

print(ans)
# Judge status: Accepted
s = list(input())
k = int(input())
t = list(map(lambda x:ord(x)-ord("a"),s))
 
for i in range(len(t)):
  diff = 26-t[i]
  if diff != 26 and diff <= k: 
    t[i]+=diff
    k-=diff
t[-1]+=k
 
u = "".join(list(map(lambda x:chr((x%26+ord("a"))),t)))
print(u)
# Judge status: Accepted
x,y = map(int,input().split())
k = abs(abs(x)-abs(y))
if x < 0 and y <= 0 or x >= 0 and y > 0:
  if x > y:
    k += 2
else:
  k += 1
print(k)
# Judge status: Accepted
s = input()
import sys
n = len(s)
kisuu = ["R","U","D"]
guusuu = ["L","U","D"]

for i in range(n):
    if i%2 == 0:
        if s[i] not in kisuu:
            break
    else:
        if s[i] not in guusuu:
            break
else:
    print("Yes")
    sys.exit()
print("No")
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
L = {}
for i in range(len(a)):
    L[i] = a[i]
sort_L = sorted(L.items(), key=lambda x: x[1])
[print(j[0]+1, end=' ')for j in sort_L]
# Judge status: Wrong Answer
N, A, B, C, D = [int(_) for _ in input().split()]
S = input()

if "##" in S[A-1:C] or "##" in S[B-1:D]:
    print("No")
elif C < D:
    print("Yes")
elif "..." in S[B-1:D]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
a, b = list(map(int, input().split()))
print(a*b)
# Judge status: Accepted
A, B, X = map(int, input().split())
print("YES" if A <= X <= A+B else "NO")