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

import sys

def main():
    s = [ord(a)-97 for a in list(sys.stdin.readline().rstrip())]
    t = [ord(b)-97 for b in list(sys.stdin.readline().rstrip())]
    l1 = len(s)
    l2 = len(t)

    dp = [[0]*(l2+1) for _ in range(l1+1)]

    for i in range(1,l1+1):
        for j in range(1,l2+1):
            if s[i-1] == t[j-1]:
                dp[i][j] = dp[i-1][j-1] + 1
            else:
                dp[i][j] = max(dp[i-1][j],dp[i][j-1])

    string = []
    for i,j in zip([m for m in range(l1,0,-1)],[n for n in range(l2,0,-1)]):
        if dp[i][j] > dp[i-1][j-1]:
            string.insert(0,chr(s[i-1]+97))
    print("".join(string))


main()



### FIXED CODE ###

import sys

s = [ord(a)-97 for a in list(sys.stdin.readline().rstrip())]
t = [ord(b)-97 for b in list(sys.stdin.readline().rstrip())]
len_s = len(s)
len_t = len(t)

dp = [[0] * (len_t+1) for i in range(len_s+1)]
for i in range(len_s):
    for j in range(len_t):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

strings = []
while len_s > 0 and len_t > 0:
    if s[len_s-1] == t[len_t-1]:
        len_s -= 1
        len_t -= 1
        strings.insert(0,chr(s[len_s]+97))
    elif dp[len_s][len_t-1] > dp[len_s-1][len_t]:
        len_t -= 1
    else:
        len_s -= 1

print("".join(strings))
### BUGGY CODE ###

from bisect import*
from numpy import*
n=int(input())
a=sorted(map(int,input().split()))
b=sorted(map(int,input().split()))
c=sorted(map(int,input().split()))
#print(a,b,c)
#print([bisect_right(b,t)for t in a])
#print(cumsum([n-bisect_right(c,s)for s in b][::-1])[::-1])
ans=0
for i in [bisect_right(b,t)for t in a]:
    if i<n:
        ans+=cumsum([n-bisect_right(c,s)for s in b][::-1])[::-1][i]
print(ans)

### FIXED CODE ###

from bisect import*
from numpy import*
n=int(input())
a=sorted(map(int,input().split()))
b=sorted(map(int,input().split()))
c=sorted(map(int,input().split()))
#print(a,b,c)
#print([bisect_right(b,t)for t in a])
#print(cumsum([n-bisect_right(c,s)for s in b][::-1])[::-1])
ans=0
x=cumsum([n-bisect_right(c,s)for s in b][::-1])[::-1]
y=[bisect_right(b,t)for t in a]
for i in y:
    if i<n:
        ans+=x[i]
print(ans)
### BUGGY CODE ###

from itertools import product

def sol():
    N = int(input())
    XYP = [tuple(map(int, input().split())) for _ in range(N)]
    X = [x for x, _, _ in XYP]
    Y = [y for _, y, _ in XYP]
    P = [p for _, _, p in XYP]
    INF = 10**18

    def calcCost(AP, A):
        ret = [[INF] * N for _ in range(1 << N)]
        for state in range(1 << N):
            useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
            for i, (a, p) in enumerate(AP):
                cost = abs(a)
                for z in useA:
                    cost = min(cost, abs(a - z))
                ret[state][i] = cost * p
        return ret

    costX = calcCost([(x, p) for x, _, p in XYP], X)
    costY = calcCost([(y, p) for _, y, p in XYP], Y)

    ans = [INF] * (N + 1)
    for state in product((0, 1, 2), repeat=N):
        stateX = 0
        stateY = 0
        M = N
        for s in state:
            stateX <<= 1
            stateY <<= 1
            if s == 0: M -= 1
            if s == 1: stateX |= 1
            if s == 2: stateY |= 1

        cx, cy = costX[stateX], costY[stateY]
        cost, an = 0, ans[M]
        for s in map(min, zip(cx, cy)):
            cost += s
            if cost >= an:
                break
        else:
            ans[M] = cost

    print(*ans, sep='\n')

sol()

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
from numba import njit
import numpy as np
INF = 10**18

@njit('(i8, i8[:,:])')
def solve(N, XYP):
    X = XYP[:, 0]
    Y = XYP[:, 1]

    def calcCost(sign, A):
        ret = np.ones((1 << N, N), dtype=np.int64) * INF
        for state in range(1 << N):
            useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
            for i in range(N):
                xyp = XYP[i]
                cost = abs(xyp[sign])
                for z in useA:
                    cost = min(cost, abs(xyp[sign] - z))
                ret[state][i] = cost * xyp[2]
        return ret

    costX = calcCost(0, X)
    costY = calcCost(1, Y)
    ans = np.ones(N + 1, dtype=np.int64) * INF

    for state in range(pow(3, N)):
        stateX = 0
        stateY = 0
        M = N
        for _ in range(N):
            state, r = divmod(state, 3)
            stateX <<= 1
            stateY <<= 1
            if r == 0: M -= 1
            if r == 1: stateX |= 1
            if r == 2: stateY |= 1

        cx, cy = costX[stateX], costY[stateY]
        cost = 0
        for i in range(N):
            cost += min(cx[i], cy[i])
        ans[M] = min(ans[M], cost)

    for a in ans:
        print(a)

def sol():
    N = int(input())
    XYP = np.asarray([list(map(int, input().split())) for _ in range(N)])
    solve(N, XYP)

sol()
### BUGGY CODE ###

# coding: utf-8
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
p =list(map(int,input().split()))
pp =[]
for i in range(len(p) - k + 1):
  tmp = 0
  for j in range(k):
    tmp += p[i+j]
  pp.append(tmp)
mn = max(pp)
ans = (mn + k) / 2
print(ans)

### FIXED CODE ###

# coding: utf-8
n, k = map(int, input().split())
p = list(map(int, input().split()))
pm = pp = sum(p[0:k])
for i in range(n - k):
    pp = pp - p[i] + p[k+i]
    pm = pp if (pp >= pm) else pm
ans = (pm + k) / 2
print(ans)
### BUGGY CODE ###

from functools import reduce
import math
import copy
def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    X = list(int(_) for _ in input().split())
    X_tmp = copy.deepcopy(X)
    X_tmp.sort()
    for i in range(N):
        if X_tmp.index(X[i]) >= N/2:
            print(X_tmp[(N//2)-1])
        else:
            print(X_tmp[(N//2)])
            
if __name__ == '__main__':
    main()


### FIXED CODE ###

from functools import reduce
import math
import copy
def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    X = list(int(_) for _ in input().split())
    X_tmp = copy.deepcopy(X)
    X_tmp.sort()
    X_avg = (X_tmp[(N//2)-1] + X_tmp[(N//2)])/2
    for i in range(N):
        if X[i] > X_avg:
            print(X_tmp[(N//2)-1])
        else:
            print(X_tmp[(N//2)])
            
if __name__ == '__main__':
    main()
### BUGGY CODE ###

s=input()
l=len(s)

dp=[4*[0]for _ in range(l+1)]
dp[0][0]=1

for i in range(1,l+1):
  si = s[i-1]
  if si == "?":
    dp[i][0] = dp[i-1][0] * 3
    dp[i][1] = dp[i-1][1] * 3
    dp[i][2] = dp[i-1][2] * 3
    dp[i][3] = dp[i-1][3] * 3
  else:
    dp[i][0] = dp[i-1][0]
    dp[i][1] = dp[i-1][1]
    dp[i][2] = dp[i-1][2]
    dp[i][3] = dp[i-1][3]
    
  if si == "A":
    dp[i][1] = dp[i-1][0] + dp[i][1]
  elif si == "B":
    dp[i][2] = dp[i-1][1] + dp[i][2]
  elif si == "C":
    dp[i][3] = dp[i-1][2] + dp[i][3]
  else:
    dp[i][1] = dp[i-1][0] + dp[i][1]
    dp[i][2] = dp[i-1][1] + dp[i][2]
    dp[i][3] = dp[i-1][2] + dp[i][3]
  
print(int(dp[-1][-1] % 1000000007))

### FIXED CODE ###

s=input()
l=len(s)

dp=[4*[0]for _ in range(l+1)]
dp[0][0]=1

for i in range(1,l+1):
  si = s[i-1]
  if si == "?":
    dp[i][0] = dp[i-1][0] * 3
    dp[i][1] = dp[i-1][1] * 3
    dp[i][2] = dp[i-1][2] * 3
    dp[i][3] = dp[i-1][3] * 3
  else:
    dp[i][0] = dp[i-1][0]
    dp[i][1] = dp[i-1][1]
    dp[i][2] = dp[i-1][2]
    dp[i][3] = dp[i-1][3]
    
  if si == "A":
    dp[i][1] = dp[i-1][0] + dp[i][1]
  elif si == "B":
    dp[i][2] = dp[i-1][1] + dp[i][2]
  elif si == "C":
    dp[i][3] = dp[i-1][2] + dp[i][3]
  else:
    dp[i][1] = dp[i-1][0] + dp[i][1]
    dp[i][2] = dp[i-1][1] + dp[i][2]
    dp[i][3] = dp[i-1][2] + dp[i][3]
  
  for j in range(4):
    dp[i][j] = dp[i][j] % 1000000007
  
print(int(dp[-1][-1]))
### BUGGY CODE ###

def sol(x):
  num = P
  for i in range(N):
    if num%x!=0:return False
    else:num/=x
  return True
  

N,P=map(int,input().split())
for x in range(int(P**(1/N))+1,0,-1):
  if sol(x):
    print(x)
    exit()


### FIXED CODE ###

def primes(n):
  ps = {}
  while n%2==0:
    n//=2
    if 2 not in ps:
      ps[2] = 1
    else:
      ps[2] += 1
  
  for i in range(3,int(n**.5)+1,2):
    while n%i==0:
      n//=i
      if i not in ps:
        ps[i] = 1
      else:
        ps[i] += 1
  
  if n!=1:
    ps[n] = 1
  
  return ps
  
N,P = map(int,input().split())
if N==1:
  print(P)
  exit()
ps = primes(P)
ans = 1
for p, num in ps.items():
  if num>=N:
    ans *= p**(num//N)
print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))
c=[0]*n
for i in range(1,n):
  hn=h[i]
  c[i]=min([ abs(h[i]-h[i-j])+c[i-j] for j in range(1,k+1) if i-j>=0])
print(c[n-1])

### FIXED CODE ###

n, k = map(int, input().split())
hs = list(map(int, input().split()))
dp=[0]*n
dp[0]=0
for i, hi in enumerate(hs):
    if i == 0:
        continue
    s = max(0, i-k)
    dp[i] = min([ml + abs(hl - hi) for ml, hl in zip(dp[s:i], hs[s:i])])
print(dp[-1])
### BUGGY CODE ###

S=str(input())
Slist=list(S)
horyu=[]
Slen=len(S)
count=0
for i in range(Slen):
    if Slist[i] == "0":
        if "1" in horyu:
            horyu.remove("1")
            count+=1
        else:
            horyu.append("0")
    else:
        if "0" in horyu:
            horyu.remove("0")
            count+=1
        else:
            horyu.append("1")
print(count*2)

### FIXED CODE ###

S=str(input())
Slist=list(S)
onecount=Slist.count("1")
zerocount=Slist.count("0")
print(2*min(zerocount,onecount))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
def main():
  n = int(input())
  xl = []
  ans = 0
  for i in range(n):
    xl.append(list(map(int, input().split())))
    xl.sort(key = lambda x:x[1])
    road = set()
  for i in range(n):
    sub = {}
    location = xl[i][0]
    arm = xl[i][1]
    sub = {j for j in range(location-arm+1, location+arm)}
    num_sub = len(sub)
    num_road = len(road)
    Z = road|sub
    if len(Z) ==num_sub + num_road:
      road = Z
      ans += 1

  print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

n = int(input())
X = []
for i in range(n):
  x, l = map(int, input().split())
  X.append([x-l, x+l])
X.sort()
temp = X[0][1]
count = n
for i in range(1,n):
  if temp>X[i][0]:
    count -= 1
    temp = min(temp, X[i][1])
  else:
    temp = X[i][1]
print(count)
### BUGGY CODE ###

s=input()
t=input()
S=[0 for i in range(26)]
T=[0 for i in range(26)]
for i in range(len(s)):
    S[ord(s[i])-97]=int(str(S[ord(s[i])-97])+str(i))  
for i in range(len(t)):
    T[ord(t[i])-97]=int(str(T[ord(t[i])-97])+str(i))  
ss=sorted(S)
tt=sorted(T)
if ss==tt:
    print('Yes')
else:print('No')

### FIXED CODE ###

#アルファベットの1対1置換が存在すればYes
S=input()
T=input()
#dは、アルファベットの置換、置換は辞書で書く
d={}
#Sを順にみていって、d内になかったらSのi番目とdのi番目が置換関係にある
for i in range(len(S)):
    if S[i] not in d:
        d[S[i]]=T[i] 
    else:
      #1対1の置換でないと判明したらNoを出力
        if d[S[i]]!=T[i]:
            print('No')
            exit()
d={}
for i in range(len(T)):
    if T[i] not in d:
        d[T[i]]=S[i]
    else:
        if d[T[i]]!=S[i]:
            print('No')
            exit()
print('Yes')
### BUGGY CODE ###

def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    visit = [1]
    s = 0
    for i in range(1,n):
        if a[s] in visit:
            l = len(visit)
            ind = visit.index(a[s])
            loop = visit[ind:]
            break
        visit.append(a[s])
        s = a[s]-1
    if l>k:
        print(visit[k])
    else:
        k = k-l
        print(loop[k%len(loop)])

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    visited = [0 for i in range(n)]
    visit = [0]
    visited[0]=1
    s = 0
    while True:
        s = a[s]-1
        if visited[s]==1:
            x = visit[0:visit.index(s)]
            y = visit[visit.index(s):]
            break
        visit.append(s)
        visited[s]=1

    if k<len(x):
        print(x[k]+1)
    else:
        k = k-len(x)
        print(y[k%len(y)]+1)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
l = sys.stdin.readline().strip()
N, M, K = map(int, l.split())
comb_quick = {}
mod = 998244353
C = [1]
for i in range(1, (N-1) // 2 + 2):
    next = C[-1] * (N-i) // i
    C.append(next)

res = 0

exp_quick = [1]
for i in range(N):
    exp_quick.append(exp_quick[-1] * (M-1) % mod)

for x in range(0,K+1):
    crt =  exp_quick[N-x-1] * M
    crt %= mod
    #print("start")
    idx = min(x, N-1-x)
    crt *= C[idx]
    #print("end")
    crt %= mod
    res += crt
    res %= mod

print(res)

### FIXED CODE ###

import sys
l = sys.stdin.readline().strip()
N, M, K = map(int, l.split())
comb_quick = {}
mod = 998244353
C = [1]
for i in range(1, (N-1) // 2 + 2):
    next = C[-1] * (N-i) * pow(i, mod-2, mod)
    C.append(next % mod)

res = 0

for x in range(K+1):
    crt =  (pow(M-1, N-x-1, mod) * M) % mod 
    crt %= mod
    #print("start")
    idx = min(x, N-1-x)
    crt *= C[idx]
    #print("end")
    crt %= mod
    res += crt
    res %= mod

print(res)
### BUGGY CODE ###

L=list()
R=list()
a,b=map(int,input().split())
for i in range(b):
  c,d=input().split()
  c=int(c)
  if d=="AC":
    L.append(c)
  elif d=="WA":
    if c not in L:
      R.append(c)
L=set(L)
t=len(L)
P=[1 for i in R if i in L]
s=sum(P)
print(t,s)

### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
  L=list()
  R=list()
  a,b=map(int,input().split())
  for i in range(b):
    c,d=input().split()
    c=int(c)
    if d=="AC":
      L.append(c)
    elif d=="WA":
      if c not in L:
        R.append(c)
  L=set(L)
  t=len(L)
  P=[1 for i in R if i in L]
  s=sum(P)
  print(t,s)
main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-

import sys
import math

sys.setrecursionlimit(10 ** 6)

input_line = input()
inputs = input_line.split(' ')
N, = [int(s) for s in inputs]

input_line = input()
s = list(input_line)
sl = len(s)

cand = []
for i in range(sl):
    for j in range(i+2,sl):
        if s[i]!=s[j]:
            cand.append((i,j))

ans = 0
for c in cand:
    st = c[0]
    en = c[1]
    for i in range(st+1,en):
        if i-st!=en-i and s[st]!=s[i] and s[i]!=s[en]:
            ans += 1

print(ans)



### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys
import math

sys.setrecursionlimit(10 ** 6)

input_line = input()
inputs = input_line.split(' ')
N, = [int(s) for s in inputs]

input_line = input()
s = list(input_line)
sl = len(s)

r = 0
g = 0
b = 0
for ss in s:
    if ss=='R':
        r += 1
    elif ss=='G':
        g += 1
    else:
        b += 1
ans = r*g*b

num = 0

for i in range(sl):
    for j in range(i+1, sl):
        k = j + (j - i)
        if k<sl:
            if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
                num += 1

ans -= num

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

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        tmp = factorization(a[i])
        if tmp[0][0] == 2:
            ans += tmp[0][1]

    print(ans)


### FIXED CODE ###

if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        ans += format(a[i], 'b')[::-1].find('1')

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

def getCalc(AAA, BBB):
    sum = 0
    for i in range(len(AAA)):
        sum += AAA[i] * BBB[i]
    return sum


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = list(map(int, input().split()))
    B.append(b)
    C.append(c)

total = sum(A)

AAA = []
BBB = []

for i in range(10 ** 5 + 1):
    count = A.count(i)
    if (count > 0):
        AAA.append(i)
        BBB.append(count)

for i in range(Q):
    if (B[i] in AAA):
        AAA = [C[i] if x == B[i] else x for x in AAA]
    print(getCalc(AAA, BBB))


### FIXED CODE ###


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = list(map(int, input().split()))
    B.append(b)
    C.append(c)

max_num = max(max(A), max(B), max(C))

NUM = [0] * (max_num + 1)

num_list = []

for a in A:
    NUM[a] += 1

total = sum(A)

for i in range(Q):

    total += (C[i] - B[i]) * NUM[B[i]]
    NUM[B[i]], NUM[C[i]] = 0, NUM[B[i]] + NUM[C[i]]

    print(total)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
def f(a,b):
    if b==0:
        return a
    else:
        return f(b,a%b)
a = sorted(a)
ans = float('inf')
for i in range(len(a)-1):
    for j in range(i+1,len(a)):
        ans = min(ans,f(a[i],a[j]))
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
memo = {}
def f(a,b):
    if b==0:
        return a
    else:
        return f(b,a%b)
a = sorted(a)
ans = float('inf')
for i in range(len(a)-1):
    ans = min(ans,f(a[i],a[i+1]))
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    h, w, m = MI()
    targets = [[] for i in range(h)]
    tate = [[] for i in range(w)]
    tate_length = [0] * w
    original = []
    lengths = [0] * h
    for i in range(m):
        target = LI()
        original.append(target)
        targets[target[0] - 1].append(target[1] - 1)
        tate[target[1] - 1].append(target[0] - 1)
        lengths[target[0] - 1] += 1
        tate_length[target[1] - 1] += 1

    max_length = max(lengths)
    max_h_indexes = [i for i, x in enumerate(lengths) if x == max_length]
    semi_max_h_indexes = [i for i, x in enumerate(
        lengths) if x == max_length - 1]

    for j in range(len(tate)):
        tate[j] = set(tate[j])
    ans = 0

    for index in max_h_indexes:
        for j in range(w):
            if index in tate[j]:
                ans = max(ans, tate_length[j] + lengths[index] - 1)
            else:
                ans = max(ans, tate_length[j] + lengths[index])
    for index in semi_max_h_indexes:
        for j in range(w):
            if index in tate[j]:
                ans = max(ans, tate_length[j] + lengths[index] - 1)
            else:
                ans = max(ans, tate_length[j] + lengths[index])

    print(ans)


main()


### FIXED CODE ###

#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    h, w, m = MI()
    targets = [[] for i in range(h)]
    tate = [[] for i in range(w)]
    tate_length = [0] * w
    original = []
    lengths = [0] * h
    for i in range(m):
        target = LI()
        original.append(target)
        targets[target[0] - 1].append(target[1] - 1)
        tate[target[1] - 1].append(target[0] - 1)
        lengths[target[0] - 1] += 1
        tate_length[target[1] - 1] += 1

    max_length = max(lengths)
    max_length_tate = max(tate_length)

    max_w_indexes = [i for i, x in enumerate(
        tate_length) if x == max_length_tate]

    max_h_indexes = [i for i, x in enumerate(
        lengths) if x == max_length]

    max_h_indexes = set(max_h_indexes)
    max_w_indexes = set(max_w_indexes)

    ttl = len(max_h_indexes) * len(max_w_indexes)

    for target in original:
        if target[0] - 1 in max_h_indexes and target[1] - 1 in max_w_indexes:
            ttl -= 1

    if ttl > 0:
        print(max_length + max_length_tate)
    else:
        print(max_length+max_length_tate - 1)


main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n, q = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]
D = [int(input()) for i in range(q)]

E = []
F = [0] * n
for i in range(n):
    s = A[i][0]
    t = A[i][1]
    x = A[i][2]
    E.append([s-x, i, 1])
    E.append([t-x, i, -1])
E.append([10**10, 10**10, 1])

E.sort()

# print(E)

from heapq import heappush, heappop
Q = []

for i in range(q):
    j = 0
    while E[j][0] <= D[i]:
        if E[j][2] == 1:
            F[E[j][1]] = 1
            heappush(Q, [A[E[j][1]][2], E[j][1]])
        else:
            F[E[j][1]] = 0
        j += 1
    
    while len(Q) > 0:
        ans = heappop(Q)
        if F[ans[1]] == 1:
            heappush(Q, ans)
            break
    if len(Q) == 0:
        print(-1)
    else:
        print(ans[0])


### FIXED CODE ###

import sys
input = sys.stdin.readline
n,q = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]
D = [int(input()) for i in range(q)]

E = []
F = {}
for i in range(n):
    s = A[i][0]
    t = A[i][1]
    x = A[i][2]
    F[x] = 0
    E.append((s-x, x, 1))
    E.append((t-x, x, -1))
E.append((10**10, 10**10, 1))

E.sort()

# print(E)

from heapq import heappush, heappop
Q = []

j = 0
for i in range(q):
    # print(F,j)
    while E[j][0] <= D[i]:
        if E[j][2] == 1:
            F[E[j][1]] += 1
            heappush(Q, E[j][1])
        else:
            F[E[j][1]] -= 1
        j += 1
    
    while len(Q) > 0 and F[Q[0]] == 0:
        _ = heappop(Q)
    if len(Q) == 0:
        print(-1)
    else:
        print(Q[0])