Harryxun/stf_run huggingface dataset:
while 1:
 H, W = map(int,raw_input().split())
 if H + W == 0:
???break
 for h in range(H):
  if h % 2 == 0:
   if W % 2 == 0:
    print ('#.'*(W//2))
   else:
    print ('#.'*(W//2)+'#')
   elif: W % 2 == 0:
     print ('.#'*(W//2))
    else:
     print ('.#'*(W//2)+'.')
    print ''

### FIXED CODE ###

while 1:
 H, W = map(int,raw_input().split())
 if H + W == 0:break
 for h in range(H):
  if h % 2 == 0:
   if W % 2 == 0:
    print ('#.'*(W//2))
   else:
    print ('#.'*(W//2)+'#')
  else:
   if W % 2 == 0:
    print ('.#'*(W//2))
   else:
    print ('.#'*(W//2)+'.')
 print ''
n = int(input())
x = [int(i) for i in input().split()]



a = statistics.median(sorted(x)[0:len(x)-1])
b = statistics.median(sorted(x)[1:len(x)])
for i in x:
    if i > a:
        print(a)
    else:
        print(b)

### FIXED CODE ###

n = int(input())
xm = list(map(int, input().split()))
xm_sort = sorted(xm)
a = n//2-1
for i in range(n):
    if xm[i]<=xm_sort[a]:
        print(xm_sort[a+1])
    else:
        print(xm_sort[a])
S = input()
if S = "AAA" or S = "BBB":
  print("No")
else:
  print("Yes")

### FIXED CODE ###

S = input()
if S == "AAA" or S == "BBB":
  print("No")
else:
  print("Yes")
from collections import defaultdict

N, Q = map(int, input().split())
tree = defaultdict(list)
counter = [0] * N
for i in range(N-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

for j in range(Q):
    p, x = map(int, input().split())
    counter[p-1] += x

visited = [False] * N


def dfs(parent):
    visited[parent] = True
    for child in tree[parent]:
        if not visited[child]:
            counter[child] += counter[parent]
            dfs(child)


dfs(0)
print(' '.join(map(str, counter)))


### FIXED CODE ###

from collections import defaultdict, deque

N, Q = map(int, input().split())
tree = defaultdict(list)
counter = [0] * N
for i in range(N-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

for j in range(Q):
    p, x = map(int, input().split())
    counter[p-1] += x

visited = [False] * N

queue = deque()
queue.append(0)
while queue:
    parent = queue.popleft()
    visited[parent] = True
    for child in tree[parent]:
        if not visited[child]:
            counter[child] += counter[parent]
            queue.append(child)

print(' '.join(map(str, counter)))
import sys

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

A.sort(reverse=True)

P = []
M = []
Ans = []
p = 0
m = 0

for i in range(N):
    if 0 <= A[i]:
        P.append(A[i])
    else:
        M.append(A[i])

M.sort()

if K % 2 == 1 and len(P) != 0:
    Ans.append(P[p])
    p += 1
elif K % 2 == 1 and len(P) == 0:
    M.sort(reverse=True)
elif len(M) == 0:
    answer = 1
    for i in range(K):
        answer = (answer * P[i]) % 1000000007

    print(answer)
    sys.exit()

while len(Ans) < K:

    #Mのストックがもうない時
    if m+1 >= len(M) and p < len(P):
        Ans.append(P[p])
        if len(Ans) == K:
            break
        Ans.append(P[p + 1])
        p += 2
    elif p+1 >= len(P) and m < len(M):
        Ans.append(M[m])
        if len(Ans) == K:
            break
        Ans.append(M[m + 1])
        m += 2
    elif m >= len(M):
        Ans.append(P[p])
        p += 1
    elif p >= len(P):
        Ans.append(M[m])
        m += 1
    else:
        if P[p]*P[p+1] < M[m]*M[m+1]:
            Ans.append(M[m])
            Ans.append(M[m+1])
            m += 2
        else:
            Ans.append(P[p])
            Ans.append(P[p + 1])
            p += 2

answer = 1
for i in range(K):
    answer = (answer * Ans[i]) % 1000000007

print(answer)


### FIXED CODE ###

import sys

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

A.sort(reverse=True)

P = []
M = []
Ans = []
p = 0
m = 0

for i in range(N):
    if 0 <= A[i]:
        P.append(A[i])
    else:
        M.append(A[i])

M.sort()

if K % 2 == 1 and len(P) != 0:
    Ans.append(P[p])
    p += 1
elif K % 2 == 1 and len(P) == 0:
    M.sort(reverse=True)
elif len(M) == 0:
    answer = 1
    for i in range(K):
        answer = (answer * P[i]) % 1000000007

    print(answer)
    sys.exit()

while len(Ans) < K:

    #Mのストックがもうない時
    if m+1 >= len(M) and p < len(P):
        Ans.append(P[p])
        if len(Ans) == K:
            break
        if p + 1 < len(P):
            Ans.append(P[p + 1])
            p += 2
        else:
            p += 1
        
    elif p+1 >= len(P) and m < len(M):
        Ans.append(M[m])
        if len(Ans) == K:
            break
        Ans.append(M[m + 1])
        m += 2
    elif m >= len(M) and p < len(P):
        Ans.append(P[p])
        p += 1
    elif p >= len(P) and m < len(M):
        Ans.append(M[m])
        m += 1
    else:
        if P[p]*P[p+1] < M[m]*M[m+1]:
            Ans.append(M[m])
            Ans.append(M[m+1])
            m += 2
        else:
            Ans.append(P[p])
            Ans.append(P[p + 1])
            p += 2

answer = 1
for i in range(K):
    answer = (answer * Ans[i]) % 1000000007

print(answer)
N, K = [int(x) for x in input().split()]

if N == 0:
    print(0)
elif K == 0:
    print(N)

t1 = abs(N - K)
t2 = K // t1

if t2 > N:
    print(N)
else:
    print(t2)

### FIXED CODE ###

def main():
    N, K = list(map(int, input().split()))
    m = N % K
    m = min(m, abs(K-m))
    print(m)
 
if __name__ == '__main__':
    main()
N=int(input("enter number")) 
even=0
odd=0
if N%2==0:
    even=N/2
    odd=N/2
else:
    even=N//2
    odd=(N//2) +1
Print(even*odd)

### FIXED CODE ###

n=int(input())
e=int(n/2)
if n%2:
	o=int(n/2+1)
else:
	o=int(n/2)
	
print (o*e)
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
result = 'No'

n = int(input())
for i in range(n):
	In = int(input())
    
	a1 = ['' if a1[j] == In else a1[j] for j in range(3)]
	a2 = ['' if a2[j] == In else a2[j] for j in range(3)]
	a3 = ['' if a3[j] == In else a3[j] for j in range(3)]
    
# tate
for i in range(2):
	if a1[i] == '' and a2[i] == '' and a3[i] == '':
		result = 'Yes'
		break
# yoko
if a1.count('') == 3:
		result = 'Yes'
if a2.count('') == 3:
		result = 'Yes'
if a3.count('') == 3:
		result = 'Yes'

# naname
if a1[0] == '' and a2[1] == '' and a3[2] == '':
		result = 'Yes'
    
if a1[2] == '' and a2[1] == '' and a3[3] == '':
		result = 'Yes'
print(result)

### FIXED CODE ###

a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
result = 'No'

n = int(input())
for i in range(n):
	In = int(input())
    
	a1 = ['' if a1[j] == In else a1[j] for j in range(3)]
	a2 = ['' if a2[j] == In else a2[j] for j in range(3)]
	a3 = ['' if a3[j] == In else a3[j] for j in range(3)]
    
# tate
for i in range(3):
	if a1[i] == '' and a2[i] == '' and a3[i] == '':
		result = 'Yes'
		break
# yoko
if a1.count('') == 3:
		result = 'Yes'
if a2.count('') == 3:
		result = 'Yes'
if a3.count('') == 3:
		result = 'Yes'

# naname
if a1[0] == '' and a2[1] == '' and a3[2] == '':
		result = 'Yes'
    
if a1[2] == '' and a2[1] == '' and a3[0] == '':
		result = 'Yes'
print(result)
import bisect

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

ans = [A[0]]
for i in range(1, N):
    index = bisect.bisect_left(ans, A[i])
    if index > 0:
        ans[index] = A[i]
    else:
        ans.insert(0, A[i])

print(len(ans))


### FIXED CODE ###

import bisect
from collections import deque

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

ans = deque([A[0]])
for i in range(1, N):
    index = bisect.bisect_left(ans, A[i])
    if index > 0:
        ans[index - 1] = A[i]
    else:
        ans.appendleft(A[i])

print(len(ans))
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

N = int(sys.stdin.readline())
A = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
Q = int(sys.stdin.readline())
BC = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(Q)) # multi line with multi param
co = collections.Counter(A)
s = sum(A)

for b,c in BC:
    if b in co:
        n = co[b]
        del(co[b])
        co[c] += n
        s += (c-b)*n
    print(s)

### FIXED CODE ###

#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys

N = int(sys.stdin.readline())


def Base_10_to_n(X, n):
    m = chr(X%n+ord("a"))
    if (X//n):
        return Base_10_to_n(X//n-1, n)+m
    return m

print(Base_10_to_n(N-1,26))
n = int(input())
s = input()
count = 0
f0,f1 = -1,-1
for ans in range(1000):
  f0,f1 = -1,-1
  ans_str = "{0:03d}".format(ans)
  for i in range(n):
    if s[i] == ans_str[0]:
      f0 = i
      break
  if f0 == -1:
    continue
  for j in range(f0+1,n):
    if s[j] == ans_str[1]:
      f1 = j
      break
  if f1 == -1:
    continue
  for k in range(f1+1,n):
    if s[k] == ans_str[2]:
      count += 1
      break

print(count)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
AB = [list(map(int,readline().split())) for i in range(N-1)]

graph = [[] for _ in range(N+1)] #隣接リスト
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

#親のノードに子を入れてくdfs
stack = [1]
parent = [0]*(N+1)
order = []
while stack:
    x = stack.pop()
    order.append(x)
    for i in graph[x]:
        if i == parent[x]:
            continue
        parent[i] = x
        stack.append(i)

#各子の色を決めていく。
color = [-1]*(N+1)
for x in order:
    ng = color[x]
    c = 1
    for y in graph[x]:
        if parent[x] == y:
            continue
        if c == ng:
            c += 1
        color[y] = c
        c += 1

ans = []
for a,b in AB:
    if parent[a] == b: #子の頂点の色を入れる
        ans.append(color[a])
    else:
        ans.append(color[b])

print(max(ans))
for i in ans:
    print(i)
N, M = list(map(int, input().split()))
G = [[] for _ in range(N+1)]
x = [None] * (N+1)

def fail():
    print("No")
    exit()

def dfs(s):
    for t, d in G[s]:
        if x[t] is None:
            x[t] = x[s] + d
            dfs(t)
        else:
            if x[t] != x[s] + d:
                fail()

for _ in range(M):
    L, R, D = map(int, input().split())
    G[L].append([R,  D])
    G[R].append([L, -D])

for i in range(N):
    if x[i] is None:
        x[i] = 0
        dfs(i)

print("Yes")

### FIXED CODE ###

import sys
sys.setrecursionlimit(200002)

N, M = map(int, input().split())
G = [[] for _ in range(N)]
x = [None] * (N)

def dfs(s):
    global x, G
    for t, d in G[s]:
        if x[t] is None:
            x[t] = x[s] + d
            if not dfs(t):
                return False
        else:
            if x[t] != x[s] + d:
                return False
    return True

for _ in range(M):
    L, R, D = map(int, input().split())
    G[L-1].append([R-1,  D])
    G[R-1].append([L-1, -D])

ans = True
for i in range(N):
    if x[i] is None:
        x[i] = 0
        ans &= dfs(i)

print("Yes" if ans else "No")
a,b,c,d = map(int,input(). split ())
print(a*b)

### FIXED CODE ###

a,b = map(int,input(). split ())
print(a*b)
n, k = map(int, input().split())
s = list(input())

# 累積和
a = [0]
if s[0] == "0":
	a.append(0)
for i in range(n):
	if i == n-1 or s[i+1] != s[i]:
		a.append(i+1) # 累積和

# print(s[-1])
if s[-1] == "0":
	a.append(s[-1])

if len(a) <= 2*k+1: # 2*k+1
	print(n)
else:
	ans = 0
	for j in range(0, len(a) - 2*k - 1, 2): # len(a)は奇数
		ans = max(ans, a[j+2*k+1] - a[j])
	print(ans)


### FIXED CODE ###

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

# 累積和
a = [0]
if s[0] == "0":
	a.append(0)
for i in range(n):
	if i == n-1 or s[i+1] != s[i]:
		a.append(i+1) # 累積和

# print(s[-1])
if s[-1] == "0":
	a.append(a[-1])

if len(a) <= 2*k+1: # 2*k+1
	print(n)
else:
	ans = 0
	for j in range(0, len(a) - 2*k - 1, 2): # len(a)は奇数
		ans = max(ans, a[j+2*k+1] - a[j])
	print(ans)
r,d,x = map(int,input())

for i in range(10):
  x = r*x - d
  print(r)

### FIXED CODE ###

r,d,x = map(int,input().split())
 
for i in range(10):
  x = r*x - d
  print(x)
l=map(int,input().split())
print(l.index(0))

### FIXED CODE ###

l=list(map(int,input().split()))
print(l.index(0)+1)
N,K = map(int,input().split())
S = input()
if S[K-1]=='A':
  S[K-1]='a'
elif S[K-1]=='B':
    S[K-1]='b'
else:
     S[K-1]='c'
print(S)

### FIXED CODE ###

N,K = map(int,input().split())
S = input()
n = K-1
ans = ""
for i in range(N):
    if i == n:
        ans = ans +S[i].lower()
    else:
        ans = ans + S[i]
print(ans)
N = int(input())
a = list(map(int,input().split()))
count=0
while(1):
    if a[0]==1:
        tmp = a[0]
        break
    else:
        count += 1
        a.pop(0)
for i in range(1,N-count):
    if a[i] == tmp + 1:
        tmp=a[i]
    else:
        count+=1
print(count)






### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
b = 1
ans = 0
for i in range(0,N):
    if a[i] == b:
        b += 1
        ans += 1
if ans == 0:
    print(-1)
else:
    print(N-ans)
import sys
input = sys.stdin.readline

def solve():
    N = int(input())
    S = list(input())
    Q = int(input())
    set_dic = {}

    for i, s in enumerate(S):
        if s not in set_dic.keys():
            set_dic[s] = {i+1}
        else:
            set_dic[s].add(i+1)

    anslist = []

    for _ in range(Q):
        query1, query2, query3 = input().split()
        if query1 == "1":
            i = int(query2)
            c = query3
            set_dic[c].discard(i)
            if c not in set_dic.keys():
                set_dic[c] = {i}
            else:
                set_dic[c].add(i)
        else:
            l = int(query2)
            r = int(query3)
            ansset = set()
            ans = 0
            for eachset in set_dic.values():
                for i in range(l, r + 1):
                    if i in eachset:
                        ans += 1
                        break
            anslist.append(ans)

    for i in anslist:
        print(i)

if __name__ == '__main__':
    solve()


### FIXED CODE ###

import bisect
import sys
input = sys.stdin.readline

def solve():
    N = int(input())
    S = list(input())
    Q = int(input())
    set_dic = {}

    for i, s in enumerate(S):
        if s not in set_dic:
            set_dic[s] = [i+1]
        else:
            bisect.insort_left(set_dic[s], i+1)

    anslist = []

    for _ in range(Q):
        query1, query2, query3 = input().split()
        if query1 == "1":
            i = int(query2)
            c = query3
            cap = S[i-1]
            if cap == c:
                continue
            set_dic[cap].remove(i)
            if c not in set_dic:
                set_dic[c] = [i]
            else:
                bisect.insort_left(set_dic[c], i)
            S[i-1] = c
        else:
            l = int(query2)
            r = int(query3)
            ansset = set()
            ans = 0
            for eachlist in set_dic.values():
                li = bisect.bisect_left(eachlist, l)
                ri = bisect.bisect_right(eachlist, r)
                if li != ri:
                    ans += 1
            anslist.append(ans)

    for i in anslist:
        print(i)

if __name__ == '__main__':
    solve()
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input().strip()
    print(s[0]+ str(lne(s)-2)+s[-1])

solve()


### FIXED CODE ###

import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input().strip()
    print(s[0]+ str(len(s)-2)+s[-1])

solve()
a,b,c,d=map(int,input().split())
if x>=0 and y>=0:
  print(b*d)
elif x>=0 and y<=0:
  print(a*d)
else:
  print(a*c)

### FIXED CODE ###

a,b,c,d=map(int,input().split())
l=[a*c, a*d, b*c, b*d]
print(max(l))
import collections
import fractions

n = int(input())
m = 0
mod = 10 ** 6 + 7
c = []
d = []
frac = {}
tmp = 0
for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        tmp += 1
        m += 1
    try:
        if b == 0: frac[float('inf')] += 1
        else: frac[fractions.Fraction(a, b)] += 1
    except KeyError:
        if b == 0: frac[float('inf')] = 1
        else: frac[fractions.Fraction(a, b)] = 1
n -= tmp

for key, value in frac.items():
    if key > 0: continue
    try:
        if key == float('inf'):
            d.append(frac[fractions.Fraction(0)])
        else:
            d.append(frac[-1 / key])
        c.append(value)
    except KeyError:
        continue

ans = pow(2, n - sum(c) - sum(d), mod)
for i, j in zip(c, d):
    tmp = (pow(2, i, mod) + pow(2, j, mod) - 1)
    ans = (ans * (pow(2, i, mod) + pow(2, j, mod) - 1)) % mod
ans -= 1 + m

print(ans)

### FIXED CODE ###

import collections
import math

n = int(input())
m = 0
mod = 10 ** 9 + 7
c = []
d = []
frac = []

for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        n -= 1
        m += 1
        continue
    if a == 0:
        frac.append('0/1')
    elif b == 0:
        frac.append(('1/0'))
    else:
        gcd = abs(math.gcd(a, b))
        sign = 1 if a * b > 0 else -1
        a = sign * abs(a) // gcd
        b = abs(b) // gcd
        frac.append('{}/{}'.format(a, b))

frac = collections.Counter(frac)

def inverse(key):
    if key == '0/1':
        return '1/0'
    elif key == '1/0':
        return '0/1'
    elif key[0] != '-':
        a, b = key.split('/')
        return '-{}/{}'.format(b, a)
    else:
        a, b = key[1:].split('/')
        return '{}/{}'.format(b, a)

for key, value in frac.items():
    if key[0] == '-' or key[0] == '0': continue
    if frac[inverse(key)] > 0:
        c.append(value)
        d.append(frac[inverse(key)])

ans = pow(2, n - sum(c) - sum(d), mod)
for i, j in zip(c, d):
    tmp = (pow(2, i, mod) + pow(2, j, mod) - 1) % mod
    ans = ans * tmp % mod
ans = (ans - 1 + m) % mod

print(ans)
def gonext(a,b):
    if a < x-1:
        a += 1
    else:
        b += 1
        a = 0
    return(a,b)

a, b = 0, 0
ans = []
visited = [[-1, -1], [-1, -1]]
stac = 0

count = 0
final = []
while a < x and b < y:
    now = Z[a][b]
    if now % 2 == 0:
        a,b = gonext(a,b)
    else:
        stac += 1
        if stac < 2:
            visited[0] = [a,b]
            a,b = gonext(a,b)
        else:
            visited[1] = [a,b]

            l0, l1 = visited
            while not l0 == l1:
                for i in range(2):
                    if l1[i] - l0[i] > 0:
                        l0_copy = copy.deepcopy(l0)
                        l0[i] += 1
                        for j in range(2):
                            l0_copy.append(l0[j])
                        count += 1
                        final.append(l0_copy)

            stac = 0
            a, b = gonext(a, b)
            ans.append(visited)
            visited = [[-1, -1], [-1, -1]]

print(count)
for i in final:
    k = [j+1 for j in i]
    print(" ".join(list(map(str, k))))

### FIXED CODE ###


import copy
y,x = list(map(int, input().split()))
Z = [list(map(int, input().split())) for _ in range(y)]

way = 1
a, b = 0, 0
ans = []
count = 0
while a < y and b < x:
    now = Z[a][b]
    a_copy= copy.deepcopy(a)
    b_copy = copy.deepcopy(b)

    if (way == 1 and a < y-1) or (way == -1 and a > 0):
        a += way
    else:
        b += 1
        way = way*(-1)
    if not (a < y and b < x):
        break
    if now % 2 == 1:
        Z[a][b] += 1
        ans.append([a_copy, b_copy, a, b])
        count += 1

print(count)
for i in ans:
    k = [j+1 for j in i]
    print(" ".join(list(map(str, k))))
S=list(input())
sorted(S)
nd=0
while nd==0 and i<len(S):
    if S[i]==S[i+1]:
         nd=1
    i+=1
if nd==1:
    print ("no")
else:
    print ("yes")
        
    

### FIXED CODE ###

S=list(input())
S.sort()
nd=0
i=0
while nd==0 and i<len(S)-1:
    if S[i]==S[i+1]:
         nd=1
    i+=1
if nd==1:
    print ("no")
else:
    print ("yes")
a,b = [int(i) for i in input().split()]

count=0
sum=1
while(sum<b):
    sum+=a-1
    count+=1
print(count)


### FIXED CODE ###

S = input()

T = input()
count = 0

s=[]
t=[]
for i in S:
    s.append(i)
for j in T:
    t.append(j)


if s[0]==t[0]:
    count+=1
if s[1]==t[1]:
    count+=1
if s[2]==t[2]:
    count+=1

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

pa = [int(p) for p in input().split()]
pb = [int(p) for p in input().split()]

pc = []

for c in range(m):
  x, y, d = list(map(int, input().split()))
  pc.append(pa[x-1]+pa[y-1]-d)
  
min_c = min(pc)
if min_c<0:
  min_c=0
min_ab = min(pa)+min(pb)

if min_c < min_ab:
  print(min_c)
else:
  print(min_ab)

### FIXED CODE ###

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

pa = [int(p) for p in input().split()]
pb = [int(p) for p in input().split()]

pc = []

for c in range(m):
  x, y, d = list(map(int, input().split()))
  pc.append(pa[x-1]+pb[y-1]-d)
  
min_c = min(pc)
if min_c<0:
  min_c=0
min_ab = min(pa)+min(pb)

if min_c < min_ab:
  print(min_c)
else:
  print(min_ab)
import copy
N,M,K = map(int,input().split())
A = [0]*N
B = [0]*M
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = 0
b = 0

tmp = 0
ans = 0
# for i in range(200000):
#     if A[a] < B[b]:
#         if tmp <= K:
#             tmp += A[a]
#             ans += 1
#             a += 1
#     elif A[a] > B[b]:
#         if tmp <= K:
#             tmp += B[b]
#             ans += 1
#             b += 1
#     if a > len(A)-1 or b > len(B)-1:
#         break
fa = False
fb = False

while len(A) > 0 or len(B) > 0:
    AA = copy.copy(A)
    BB = copy.copy(B)
    if len(AA) != 0:
        a = AA.pop(0)
        fa = True
    if len(BB) != 0:
        b = BB.pop(0)
        fb = True
    if fa and fb:
        if a<=b:
            tmp += a
            ans += 1
            A = AA
        else:
            tmp += b
            ans += 1
            B = BB
    else:
        if fa:
            tmp += a
            ans += 1
            A = AA
        if fb:
            tmp += b
            ans += 1
            B = BB

    if tmp > K:
        break
    fa = False
    fb = False
    
    print(tmp,A,B)
    
if len(A)==0 and len(B)==0:
    print(ans)
else:
    print(ans-1)


### FIXED CODE ###

N,M,K = map(int,input().split())
A = [0]*N
B = [0]*M
A = list(map(int,input().split()))
B = list(map(int,input().split()))

b = []
b.append(0)
tmp = 0
for i in range(M):
    b.append(tmp+B[i])
    tmp = tmp+B[i]# M冊全部呼んだとする
a = [0]
for i in range(N):
    a.append(a[i]+A[i])
#print(b)
ans,j = 0,M
for i in range(N+1):
    if a[i]>K:
        break
    while b[j] > K - a[i]:#Kを超えてたらこの冊数読むの諦める
        j -= 1
    ans = max(ans,i+j)#最大冊数を更新していく

print(ans)
s=sorted(input())
if (s[0]==s[1]) and (s[2]==s[3])　and (s[0]!=s[2]):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

s=sorted(input())
if (s[0]==s[1]) and (s[2]==s[3]) and (s[0]!=s[2]):
    print("Yes")
else:
    print("No")
P, Q, R = map(int, input().split())
print(min(P+Q, Q+R, R+A))


### FIXED CODE ###

P, Q, R = map(int, input().split())
print(min(P+Q, Q+R, R+P))
N=int(input())
p = [int(input) for _ in range(len(N))]

print(sum(p) - int(max(p)/2))


### FIXED CODE ###

N=int(input())
p = [int(input()) for _ in range(N)]

print(sum(p) - int(max(p)/2))
N = int(input())
S = input()
K = int(input())
ans = ""

for i in range(N):
    if(S[K] != S[i]):
        ans += "*"
    else:
        ans += S[K]
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
K = int(input())
ans = ""

for i in range(N):
    if(S[K-1] != S[i]):
        ans += "*"
    else:
        ans += S[K-1]
print(ans)