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

N = int(input())
A = list(map(int,input().split()))
Nc = 0
e = 0
B = []
A.sort()
if N % 2 == 0:
    for i in range(1, N//2 + 1):
        B = B + [2*i - 1, 2*i -1]
    if A == B:
        Nc = 2**(N//2)
else:
    for i in range(1, ((N-1)//2) + 1):
        B = B + [2*i, 2*i]
    B = [0] + B
    if A == B:
        Nc = 2**((N-1)//2)

print(Nc%1000000007)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
Nc = 1
e = 0
B = [0]*N
for i in A:
    if (N-i-1) < 0:
        e = 1
        Nc = 0
        break
if e ==0:
    if A.count(0) >= 2:
        Nc *= 0
    else:
        if A.count(0) == 1:
            A.remove(0)
        for i in A:
            B[i] = B[i] + 1
        for i in B:
            if i == 2:
                Nc *= 2
            elif i == 0:
                Nc *= 1
            else:
                Nc *= 0
                break
print(Nc%1000000007)
### BUGGY CODE ###

x, y, a, b, c = [int(i) for i in input().split()]
lp = sorted([int(i) for i in input().split()])
if len(lp) != x:
  del lp[:len(lp)-x]
lq = sorted([int(i) for i in input().split()])
if len(lq) != y:
  del lq[:len(lq)-y]
lr = sorted([int(i) for i in input().split()])

while True:
  if len(lr) == 0:
    break
  r_max = lr[len(lr)-1]
  p_min = lp[0]
  q_min = lq[0]
  if r_max <= p_min and r_max <= q_min:
    break
  elif r_max > q_min and p_min >= q_min:
    del lq[0]
    lq.append(lr.pop(-1))
  elif r_max > p_min and q_min >= p_min:
    del lp[0]
    lp.append(lr.pop(-1))


print(sum(lp) + sum(lq))

### FIXED CODE ###

from collections import deque
x, y, a, b, c = [int(i) for i in input().split()]
lp = sorted([int(i) for i in input().split()])
if len(lp) != x:
  del lp[:len(lp)-x]
lp = deque(lp)
lq = sorted([int(i) for i in input().split()])
if len(lq) != y:
  del lq[:len(lq)-y]
lq = deque(lq)
lr = sorted([int(i) for i in input().split()])
lr = deque(lr)


while True:
  if len(lr) == 0:
    break
  r_max = lr[len(lr)-1]
  p_min = lp[0]
  q_min = lq[0]
  if r_max <= p_min and r_max <= q_min:
    break
  elif r_max > q_min and p_min >= q_min:
    del lq[0]
    lq.append(lr.pop())
  elif r_max > p_min and q_min >= p_min:
    del lp[0]
    lp.append(lr.pop())


print(sum(lp) + sum(lq))
### BUGGY CODE ###

S = input()
Q = int(input())
Query = [input() for _ in range(Q)]
flag = True
for i in range(Q):
    if Query[i][0] == "1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if Query[i][2] == '1':
            if flag:
                S = Query[i][4] + S
            else:
                S = S + Query[i][4]
        else:
            if flag:
                S = S + Query[i][4]
            else:
                S = Query[i][4] + S
if flag:
    print(S)
else:
    print(S[::-1])

### FIXED CODE ###

S = input()
Q = int(input())
Query = [input() for _ in range(Q)]
flag = True
s = "!"
for i in range(Q):
    if Query[i][0] == "1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if Query[i][2] == '1':
            if flag:
                s = Query[i][4] + s
            else:
                s = s + Query[i][4]
        else:
            if flag:
                s = s + Query[i][4]
            else:
                s = Query[i][4] + s
ans = s.replace("!", S)
if flag:
    print(ans)
else:
    print(ans[::-1])
### BUGGY CODE ###

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


def binary_search(list, key):
    l = -1
    r = len(list)

    while r - l > 1:
        mid = l + (r - l) // 2
        if list[mid] > key:
            r = mid
        else:
            l = mid

    if r < len(list):
        return r
    else:
        return -1


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 a in A:
    index_a = binary_search(B, a)
    if index_a != -1:
        for i in range(index_a, len(B)):
            index_b = binary_search(C, B[i])
            if index_b != -1:
                ans += n - index_b

print(ans)


### FIXED CODE ###

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


def higher_search(list, key):
    l = -1
    r = len(list)

    while r - l > 1:
        mid = l + (r - l) // 2
        if list[mid] > key:
            r = mid
        else:
            l = mid

    if r == len(list):
        return -1
    else:
        return r


def lower_search(list, key):
    l = -1
    r = len(list)

    while r - l > 1:
        mid = r - (r - l) // 2
        if list[mid] < key:
            l = mid
        else:
            r = mid

    if l == -1:
        return -1
    else:
        return l


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_index = lower_search(A, b)
    c_index = higher_search(C, b)
    if c_index == -1:
        c_index = n
    ans += (a_index + 1) * (n - c_index)

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

N=int(input())
if N%2==0:
  print(-1)
else:
  ans=1
  a=7
  num=7
  while(num%N!=0):
    a=(a*10)%N
    num=(num+a)%N
    ans+=1
  print(ans)
  


### FIXED CODE ###

N=int(input())
if N%2==0:
  print(-1)
elif N%5==0:
  print(-1)
else:
  ans=1
  a=7
  num=7
  while(num%N!=0):
    a=(a*10)%N
    num=(num+a)%N
    ans+=1
  print(ans)
### BUGGY CODE ###

import itertools
import collections

n = int(input())
lists = [str(input()) for i in range(n)]

lists2 = ["".join(sorted(i)) for i in lists]
l = collections.Counter(lists2)
c = l.values()

list3 = [itertools.combinations(range(i),2) for i in c]

print(len([e for inner_list in list3 for e in inner_list]))

### FIXED CODE ###

import collections

n = int(input())
lists = [str(input()) for i in range(n)]

lists2 = ["".join(sorted(i)) for i in lists]
l = collections.Counter(lists2)
c = l.values()
 
print(int(sum([i * (i - 1)/ 2 for i in c])))
### BUGGY CODE ###

N,M = (int(i) for i in input().split())
a = [int(input()) for i in range(M)]
hoge = [0] * N
if 1 not in a:
    hoge[0] = 1
if 2 not in a and N >= 2:
    hoge[1] = hoge[0] + 1

for i in range(2,N):
    if i + 1  not in a:
        hoge[i] += hoge[i - 1]
        hoge[i] += hoge[i - 2]

print(hoge[N-1] % (10**9 + 7))

### FIXED CODE ###

N, M = map(int, input().split())
A = set(int(input()) for _ in range(M))
mod = 10 ** 9 + 7

dp = [0] * (N+1)
dp[0] = 1
for i in range(1, N+1):
    if i in A:
        continue
    if i == 1:
        dp[i] = 1
        continue
    dp[i] = dp[i-1] + dp[i-2]

print(dp[N] % mod)
### BUGGY CODE ###

N,W=map(int,input().split())
weight=[0]*N
value=[0]*N
for i in range(N):
    weight[i],value[i]=map(int,input().split())
dp=[[0 for i in range(W+1)] for j in range(N+1)]
for i in range(W+1):
    dp[0][i]=0

for i in range(N):
    for w in range(W+1):
        if weight[i]<=w:
            dp[i+1][w]=max(dp[i][w-weight[i]]+value[i], dp[i][w])
        else:
            dp[i+1][w]=dp[i][w]
print(dp[N][W])


### FIXED CODE ###

N,W=map(int,input().split())
weight=[0]*N
value=[0]*N
for i in range(N):
    weight[i],value[i]=map(int,input().split())
dp=[[0 for i in range(W+1)] for j in range(N+1)]
for i in range(W+1):
    dp[0][i]=0

for i in range(N):
    for w in range(W+1):
        if weight[i]<=w:
            dp[i+1][w]=max(dp[i][w-weight[i]]+value[i], dp[i][w])
        else:
            dp[i+1][w]=dp[i][w]
print(dp[N][W])
### BUGGY CODE ###

k = int(input())
s = input()

l = len(s)

N = k + l + 100
MOD = 10 ** 9 + 7
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
    fact[i] = i * fact[i - 1] % MOD

invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)

for i in range(N - 2, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % MOD
    
def nCk(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return fact[n] * invfact[k] * invfact[n - k] % MOD

ex_25 = [0 for _ in range(N)]
ex_26 = [0 for _ in range(N)]
ex_25[0] = 1
ex_26[0] = 1
for i in range(1, N):
    ex_25[i] = ex_25[i - 1] * 25 % MOD
    ex_26[i] = ex_26[i - 1] * 26 % MOD

ans = 0
for i in range(k + 1):
    ans += ex_25[i] * ex_26[k - i] * nCk(i + l - 1, i)
    ans %= MOD
    
print(ans)
    

### FIXED CODE ###

k = int(input())
s = input()

l = len(s)

N = k + l + 100
MOD = 10 ** 9 + 7
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
    fact[i] = i * fact[i - 1] % MOD

invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)

for i in range(N - 2, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % MOD
    
def nCk(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return fact[n] * invfact[k] * invfact[n - k] % MOD

ex_25 = [0 for _ in range(N)]
ex_26 = [0 for _ in range(N)]
ex_25[0] = 1
ex_26[0] = 1
for i in range(1, N):
    ex_25[i] = ex_25[i - 1] * 25 % MOD
    ex_26[i] = ex_26[i - 1] * 26 % MOD

ans = 0
for i in range(k + 1):
    ans += ex_25[i] * ex_26[k - i] * nCk(i + l - 1, i)
    ans %= MOD
    
print(ans)
### BUGGY CODE ###

import copy

n = int(input())

goal = list(map(int, input().split(" ")))

output = -1

def searchAns(goal, temp, left, proc):
  #print(temp, left, proc)
  if len(left) == 0:
    if temp == goal:
      return proc
    else:
      return -1
  for num in left:
    #print(num, temp, left, proc)
    if num <= len(temp) + 1:
      copyTemp = copy.copy(temp)
      copyTemp.insert(num-1, num)
      copyLeft = copy.copy(left)
      copyLeft.remove(num)
      copyProc = copy.copy(proc)
      copyProc.append(num)
      result = searchAns(goal, copyTemp, copyLeft, copyProc)
      if result != -1:
        return result
  else:
    return -1
    
proc = searchAns(goal, [], goal, [])

if proc == -1:
  print(-1)
else:
  for num in proc:
    print(num)

### FIXED CODE ###

import copy

n = int(input())

goal = list(map(int, input().split(" ")))

output = -1

procReverse = []

temp_goal = copy.copy(goal)

for _ in range(n):
  index = list(range(1,len(temp_goal)+1))
  for i in range(len(temp_goal)-1, -1, -1):
    #print(i, index, temp_goal)
    if index[i] == temp_goal[i]:
      procReverse.append(temp_goal[i])
      temp_goal.pop(i)
      break
  else:
    print(-1)
    break
else:
  for i in range(n-1, -1, -1):
    print(procReverse[i])
### BUGGY CODE ###

#すぬけくんの塗り絵
h,w,n=map(int,input().split())
dic={}
for  _ in range(n):
    a,b=map(int,input().split())
    for i in range(a-1,a+2):
        for j in range(b-1,b+2):
            if (i,j) in dic.keys():
                dic[(i,j)]+=1
            else:
                dic[(i,j)]=1
              
howmany=[0 for i in range(10)]
for some in dic.keys():
    a,b=some[0],some[1]
    if 2<=a<=h-1 and 2<=b<=w-1:
        howmany[dic[some]]+=1
J=(h-2)*(w-2)-sum(howmany)
print(J)
for i in range(1,10):
    print(howmany[i])

### FIXED CODE ###

#すぬけくんの塗り絵
h,w,n=map(int,input().split())
dic={}
for  _ in range(n):
    a,b=map(int,input().split())
    for i in range(a-1,a+2):
        for j in range(b-1,b+2):
            if (i,j) in dic.keys():
                dic[(i,j)]+=1
            else:
                dic[(i,j)]=1
              
howmany=[0 for i in range(10)]
for some in dic.keys():
    a,b=some[0],some[1]
    if 2<=a<=h-1 and 2<=b<=w-1:
        howmany[dic[some]]+=1
J=(h-2)*(w-2)-sum(howmany)
print(J)
for i in range(1,10):
    print(howmany[i])
### BUGGY CODE ###

# sys.stdin.readline()
import sys
input = sys.stdin.readline


def decision(s,td,index):
    #index番目の文字が落ちるかどうかを判別
    #右に落ちるときは1，左に落ちるときは-1，落ちないときは0を返す
    global N,Q
    qi = 0
    j = index
    for qi in range(Q):
        if j < 0 or j >= N:
            break
        if s[j] == td[qi][0]:
            if td[qi][1] == 'L':
                j -= 1
            elif td[qi][1] == 'R':
                j += 1
    if j == -1:
        return -1
    elif j == N:
        return 1
    else:
        return 0
    
 
 
N,Q = map(int,input().split())
s = input()
 
td = [0] * Q
for i in range(Q):
    td[i] = (input().split())
    
#td[i][j]:i番目の文字(j=0)と方向(j=1)
    
    
#2分探索
left = 0
right = N-1
#右側のボーダー
while (right - left ) != 1:
    mid = round((right+left)/2)
    state = decision(s,td,mid)
    if state < 1:
        left = mid
    else:
        right = mid
if right == N-1 and decision(s,td,right) == 0:
    right += 1
border_r = right
    
left = 0
right = N-1
#左側のボーダー
while (right - left ) != 1:
    mid = round((right+left)/2)
    state = decision(s,td,mid)
    if state > -1:
        right = mid
    else:
        left = mid
if left == 0 and decision(s,td,left) == 0:
    right -= 1
border_l = right
print(border_r-border_l)
 

### FIXED CODE ###

# sys.stdin.readline()
import math
import sys
input = sys.stdin.readline


def decision(s,td,j):
    #index番目の文字が落ちるかどうかを判別
    #右に落ちるときは1，左に落ちるときは-1，落ちないときは0を返す
    global N,Q
    for [qi,v] in td:
        if j < 0 or j >= N:
            break
        if s[j] == qi:
            if v == 'L':
                j -= 1
            else:
                j += 1
    if j == -1:
        return -1
    elif j == N:
        return 1
    else:
        return 0
 
N,Q = map(int,input().split())
s = input()
td = [input().split() for _ in range(Q)]
    
#td[i][j]:i番目の文字(j=0)と方向(j=1)
    
    
RN = math.ceil(math.log2(N))
#2分探索
left = 0
right = N-1
#右側のボーダー
for i in range(RN):
    mid = (right+left)//2
    state = decision(s,td,mid)
    if state < 1:
        left = mid
    else:
        right = mid
    if (right - left) == 1:
        break
if right == N-1 and decision(s,td,right) == 0:
    right += 1
border_r = right
    
left = 0
right = N-1
#左側のボーダー
for i in range(RN):
    mid = ((right+left)//2)
    state = decision(s,td,mid)
    if state > -1:
        right = mid
    else:
        left = mid
    if (right - left) == 1:
        break
if left == 0 and decision(s,td,left) == 0:
    right -= 1
border_l = right
print(border_r-border_l)
### BUGGY CODE ###

import math
K=int(input())+1
sum=0
for a in range(1,K):
    for b in range(1,K):
        for c in range(1,K):
            gcd1 = int(math.gcd(a,b))
            gcd2 = int(math.gcd(b,c))
            gcd = int(math.gcd(gcd1,gcd2))

            sum = sum+gcd
print(sum)

### FIXED CODE ###

from math import gcd

K = int(input())
out = 0
Count = [0]*K
gcds = [[0]*K for i in range(K)]

for i in range (1,K+1):
    for j in range(1,+K+1):
        value = gcd(i,j)
        gcds[i-1][j-1]=value
        Count[value-1]+=1

for i in range(1,K+1):
    for j in range(1,K+1):
        out +=gcds[i-1][j-1]*Count[j-1] #値*回数
        
print(out)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(500000)
def dfs(p, v, num):
    global g, plus_list, ans
    tmp = num + plus_list[v]
    for x in g[v]:
        if x == p:
            continue
        dfs(v, x, tmp)
    ans[v] = tmp
    
def main():
    global g, plus_list, ans
    N, Q = map(int, input().split())
    g = [[] for i in range(N)] 
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        g[a].append(b)
        g[b].append(a)

    plus_list = [0] * N
    for i in range(Q):
        q, y = map(int, input().split())
        plus_list[q-1] += y

    ans = [0] * N
    
    dfs(-1, 0, 0)
    print(*ans)
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def dfs(fr, now, num):
    global graph, addsum, ans
    tmp = num + addsum[now]
    for a in graph[now]:
        if a == fr:
            continue
        dfs(now, a, tmp)
    ans[now] = tmp


def main():
    global graph, addsum, ans
    N, Q = map(int, readline().split())
    graph = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, readline().split())
        a -= 1; b -= 1
        graph[a].append(b)
        graph[b].append(a)
    addsum = [0]*N
    for _ in range(Q):
        p, x = map(int, readline().split())
        p -= 1
        addsum[p] += x
    
    ans = [0]*N
    dfs(-1, 0, 0)

    print(*ans)


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

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

for x in range(1,n+1):
    print(a.index(x)+1, end=' ')


### FIXED CODE ###

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

d = {}
for i in range(n):
    d[a[i]] = i+1

for i in range(1,n+1):
    print(d[i], end=" ")
### BUGGY CODE ###

n= int(input())
s = str(input())
count = 0
r = []
g = []
b = []
for i in range(n):
    if s[i]=="R":
        r.append(i)
    elif(s[i]=="G"):
        g.append(i)
    elif(s[i]=="B"):
        b.append(i)
# print(r)
# print(b)
count=0
for i in r:
    for j in g:
        for k in b:
            if abs(j-i)!=abs(k-j) and abs(j-i)!=abs(k-i) and(abs(k-i)!=abs(k-j)):
                count +=1
print(count)

### FIXED CODE ###

n= int(input())
s = str(input())

r=set()
g=set()
b=set()
for i in range(n):
    if s[i]=='R':
        r.add(i)
    if s[i]=='G':
        g.add(i)
    if s[i]=='B':
        b.add(i)
score = len(r)*len(g)*len(b)
for i in r:
    for j in g:
        dist=abs(j-i)
        if (i>j):
            bi = i+dist
            if bi in b:
                score -=1
            bi = j-dist
            if bi in b:
                score -=1
        else:
            bi = j+dist
            if bi in b:
                score-=1
            bi = i-dist
            if bi in b:
                score-=1
        if((i+j)%2==0 and (i+j)/2 in b):
            score-=1
# print(count_)
print(score)
### BUGGY CODE ###

N=int(input())
d=list(map(int, input().split()))
B=N
for x in range(0,N):
    for y in range(0,N-1):
        if d[y]<d[y+1]:
            t=d[y]
            d[y]=d[y+1]
            d[y+1]=t
    N=N-1
C=B//2
if d[C]==d[C-1]:
    print(0)
if d[C]!=d[C-1]:
    print(d[C-1]-d[C])


### FIXED CODE ###

N=int(input())
d=list(map(int, input().split()))
C=N//2
d.sort()
if d[C]==d[C-1]:
    print(0)
else:
    print(d[C]-d[C-1])
### BUGGY CODE ###

import math

N=int(input())
for i in range(int(math.sqrt(N)),N):
    if N % i == 0:
        a=i
        break
print(int(a+(N/a)-2))

### FIXED CODE ###

N=int(input())
for i in reversed(range(int(N**0.5)+1)):
    if N % i == 0:
        print(int(i+N//i-2))
        break
### BUGGY CODE ###

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

H = list(map(int, input().split()))
max_K = 100
for _ in range(max_K):
  H.append(float('inf'))

dp = [float('inf')] * (N + max_K)
dp[0] = 0

for n in range(N):
  for offset in range(1, K + 1):
    cost = dp[n] + abs(H[n] - H[n + offset])
    if (dp[n + offset] > cost):
      dp[n + offset] = cost

print(dp[N - 1])


### FIXED CODE ###

import sys
input = sys.stdin.readline
N, K = map(int, input().split())

# H = deque(list(map(int, input().split())))
max_K = 100
H = list(map(int, input().split()))
H += [0] * max_K
# for _ in range(max_K):
#   H.append(0)

dp = [float('inf')] * (N + max_K)
dp[0] = 0

for n in range(N):
  for offset in range(1, K + 1):
    new_index = n + offset
    cost = dp[n] + abs(H[n] - H[new_index])
    if (dp[new_index] > cost):
      dp[new_index] = cost

print(dp[N - 1])
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
l = [0] * q
r = [0] * q
for i in range(0, q):
    l[i], r[i] = map(int, input().split())
ac_index = [False] * n
for i in range(n - 1):
    if s[i] + s[i + 1] == 'AC':
        ac_index[i] = True
for i in range(0, q):
    count = 0;
    for j in range(l[i] - 1, r[i] - 1):
        if ac_index[j]:
            count += 1
    print(count)

### FIXED CODE ###

n, q = map(int, input().split())
s = ' ' + input()
heap = [0] * (n + 1)
cnt = 0
for i in range(2, n + 1):
    if s[i - 1] == 'A' and s[i] == 'C':
        cnt += 1;
    heap[i] = cnt
ans = []
for i in range(q):
    l, r = map(int, input().split())
    ans.append(heap[r] - heap[l])
for i in ans:
    print(i)
### BUGGY CODE ###

A, B, C, D = map(int, input().split())
# 追加の仕方から考えると、塗られている数はC-A + D-B
# 縦と横の長さが同じなら、その次の動作で塗れる組み合わせは同じ
# 選びうる方法を全部数え上げよう

c = C - A
d = D - B
mod = 998244353
dp = [[0]*(d+1) for i in range(c+1)]
dp[0][0] = 1

for i in range(c+1):
    for j in range(d+1):
        if i > 0 and j > 0:
            if i == j == 1:
                dp[i][j] -= (A+i-1) * (B+j-1)
            else:
                tmp = dp[i-1][j-1]
                #print(tmp, i, j)
                tmp *= (A+i-1)*(B+j-1)

                # print(dp[i][j], tmp)
                dp[i][j] -= tmp

        if i < c:
            dp[i+1][j] += dp[i][j]*(B+j)
        if j < d:
            dp[i][j+1] += dp[i][j]*(A+i)
        # print(dp)
        dp[i][j] %= mod

print(dp[c][d])

### FIXED CODE ###

def main():
    A, B, C, D = map(int, input().split())

    c = C - A
    d = D - B
    mod = 998244353
    dp = [[0]*(d+1) for i in range(c+1)]
    dp[0][0] = 1

    for i in range(c+1):

        for j in range(d+1):
            ret = 0
            if i == 0 and j == 0:
                continue
            if i > 0 and j > 0:
                if i == j == 1:
                    ret -= (A+i-1) * (B+j-1)
                else:
                    ret -= dp[i-1][j-1]
                    ret *= (A+i-1)*(B+j-1)
            ret += dp[i-1][j]*(B+j) + dp[i][j-1]*(A+i)

            ret %= mod
            dp[i][j] = ret
    print(dp[c][d])


main()
### BUGGY CODE ###

from sys import stdin


SS = stdin.readline().rstrip()
TT = stdin.readline().rstrip()

S = list(SS)
T = list(TT)

N = len(S)

ret = "Yes"

for i in range(0, N):
    if ret == "No":
        break

    for j in range(i+1, N):
        if S[i] == S[j]:
            if T[i] != T[j]:
                ret = "No"
        if T[i] == T[j]:
            if S[i] != S[j]:
                ret = "No"

print(ret)

### FIXED CODE ###

S = input()
T = input()

d1 = dict()
d2 = dict()

ret = "Yes"

for s, t in zip(S, T):
    #print("{}-->{}".format(s, t))
    tmp1 = d1.get(s, None)
    tmp2 = d2.get(t, None)
    if (tmp1 == None or tmp1 == t) and (tmp2 == None or tmp2 == s):
        d1[s] = t
        d2[t] = s
    else:
        ret = "No"

print(ret)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from bisect import bisect_left, bisect_right
INF = float("inf")


def main():
    N, Q = map(int, input().split())
    XST = [0]*N
    for i in range(N):
        s, t, x = map(int, input().split())
        XST[i] = (x, s-x, t-x)
    XST.sort(reverse=True)
    D = [0]*Q
    for i in range(Q):
        D[i] = int(input())
    stop = [-1]*Q
    # print(D)
    # Dはソートされている。ラッキー！
    for x, s, t in XST:
        # こっから！
        # print("[{}, {})".format(s, t))
        frm = bisect_left(D, s)
        # ここまで！
        to = bisect_left(D, t, lo=frm)
        # print(frm, to)
        for j in range(frm, to):
            stop[j] = x
    print(*stop, sep="\n")


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from bisect import bisect_left, bisect_right
import heapq

INF = float("inf")


class ErasableHeap(object):
    # https://qiita.com/Salmonize/items/638da118cd621d2628d1
    def __init__(self):
        self.data = []
        self.event = []

    def push(self, x):
        return heapq.heappush(self.data, x)

    def erase(self, x):
        return heapq.heappush(self.event, x)

    def _check(self):
        while self.event and\
                self.data[0] == self.event[0]:
            heapq.heappop(self.data)
            heapq.heappop(self.event)

    def front(self):
        self._check()
        return self.data[0]

    def pop(self):
        self.check()
        return heapq.heappop(self.data)

    def __len__(self):
        self._check()
        return len(self.data)


def main():
    N, Q = map(int, input().split())
    XST = [0]*N
    for i in range(N):
        s, t, x = map(int, input().split())
        XST[i] = (x, s-x, t-x)
    D = [0]*Q
    for i in range(Q):
        D[i] = int(input())
    event = []
    for x, s, t in XST:
        event.append((s, 1, x))
        event.append((t, -1, x))

    event.sort()

    head = 0
    stack = ErasableHeap()
    for t, p, x in event:
        while D[head] < t:
            if len(stack) == 0:
                print(-1)
            else:
                print(stack.front())
            head += 1
            if head >= Q:
                return
        if p == 1:
            stack.push(x)
        else:
            stack.erase(x)

    while head < len(D):
        if len(stack) == 0:
            print(-1)
        else:
            print(stack.front())
        head += 1
        if head >= Q:
            return


if __name__ == '__main__':
    main()