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

import bisect
N,D,A=map(int,input().split())
XH=[list(map(int,input().split())) for _ in range(N)]
XH.sort()
for i in range(N):
    XH[i][1]=-(-XH[i][1]//A)
X=[x for x,a in XH]
far=[0]*N
for i in range(N):
    far[i]=bisect.bisect_right(X,X[i]+2*D)-1

ans=0
for i in range(N):
    x=XH[i][0]
    hp=XH[i][1]
    if hp<=0:
        continue
    XH=[[xx,hh-hp] for xx,hh in XH[:far[i]+1]]+XH[far[i]+1:]
    #for j in range(i,far[i]+1):
    #    XH[j][1]-=hp
    ans+=hp
print(ans)

### FIXED CODE ###

import bisect
def main():
    N,D,A=map(int,input().split())
    XH=[list(map(int,input().split())) for _ in range(N)]
    XH.sort()
    for i in range(N):
        XH[i][1]=-(-XH[i][1]//A)
    X=[x for x,a in XH]
    far=[0]*N
    for i in range(N):
        far[i]=bisect.bisect_right(X,X[i]+2*D)-1

    ans=0
    carry=0
    outrange=[0]*(N+1)
    for i in range(N):
        x=XH[i][0]
        hp=XH[i][1]
        carry-=outrange[i]
        if carry>=hp:
            continue
        outrange[bisect.bisect_right(X,X[i]+2*D)]+=hp-carry
        ans+=hp-carry
        carry+=hp-carry
    print(ans)

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

from itertools import accumulate

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

def do(A):
  B = [0] * (N+2)
  for i, a in enumerate(A, 1):
    l = max(i - a, 0)
    r = min(i + a + 1, N+1)
    B[l] += 1
    B[r] -= 1
  B = list(accumulate(B))
  return B[1:-1]

def check(A):
  for a in A:
    if a < N:
      return False
  return True

for i in range(K):
  A = do(A)
  if check(A):
    print(*A)
    quit()

print(*A)

### FIXED CODE ###

from itertools import accumulate

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

def do(A):
  B = [0] * (N+2)
  for i, a in enumerate(A, 1):
    l = max(i - a, 0)
    r = min(i + a + 1, N+1)
    B[l] += 1
    B[r] -= 1
  B = list(accumulate(B))
  return B[1:-1]

def check(A):
  for a in A:
    if a < N:
      return False
  return True

for i in range(K):
  A = do(A)
  if check(A):
    print(*A)
    quit()

print(*A)
### BUGGY CODE ###

from collections import deque

H, W = map(int, input().split())
# sx, sy = map(int, input().split())
# gx, gy = map(int, input().split())
# sx, sy, gx, gy = sx-1, sy-1, gx-1, gy-1
c = [input() for i in range(H)]
INF = 10**9
def bfs():
    dist = [[INF for i in range(W)] for j in range(H)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    q = deque()
    q.append([sx, sy])
    dist[sx][sy] = 0
    while q:
        p = q.popleft()
        if p[0] == gx and p[1] == gy:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx and nx < H and 0 <= ny and ny < W:
                if c[nx][ny] != '#' and dist[nx][ny] == INF:
                    q.append([nx, ny])
                    dist[nx][ny] = dist[p[0]][p[1]] + 1
    return dist[gx][gy]

ans = []
can = []
for i in range(H):
    for j in range(W):
        for k in range(H):
            for l in range(W):
                sx, sy = i, j
                gx, gy = k, l
                if c[sx][sy] == '#' or c[gx][gy] == '#':
                    continue
                can.append((sx, sy, gx, gy))

for sx, sy, gx, gy in can:
    ans.append(bfs())
                
ans = [i for i in ans if i != INF]
print(max(ans))

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
c = [input() for i in range(H)]

INF = -1

def bfs():
    dist = [[INF for i in range(W)] for j in range(H)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    q = deque()
    q.append([sx, sy])
    dist[sx][sy] = 0
    while q:
        p = q.popleft()
        # if p[0] == gx and p[1] == gy:
        #     break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx and nx < H and 0 <= ny and ny < W:
                if c[nx][ny] != '#' and dist[nx][ny] == INF:
                    q.append([nx, ny])
                    dist[nx][ny] = dist[p[0]][p[1]] + 1
    ret = -1
    for i in range(H):
        ret = max(ret, max(dist[i]))
    return ret

ans = -1
for i in range(H):
    for j in range(W):
            sx, sy = i, j
            if c[sx][sy] == '#':
                continue
            ans = max(ans, bfs())
print(ans)
### BUGGY CODE ###

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

ans = 1

for i in a:
	ans = ans * i
	
if ans > 1000000000000000000:
	print(-1)
else:
	print(ans)


### FIXED CODE ###


n = int(input())
v = list(map(int, input().split(' ')))

ans = 1

if 0 in v:
	print(0)
	exit(0)

for item in v:
	ans = ans * item
	if ans > 1000000000000000000:
		print(-1)
		exit(0)
print(ans)
### BUGGY CODE ###

def main():
    N, K = map(int, input().split())
    S = input()
    nums = []
    now = 1
    cnt = 0
    for s in S:
        if int(s) == now:
            cnt += 1
        else:
            nums.append(cnt)
            now ^= 1
            cnt = 1
    if cnt > 0:
        nums.append(cnt)
    if len(nums) % 2 == 0:
        nums.append(0)
    add = 2 * K + 1
    ans = 0
    for cnt in range(0, len(nums), 2):
        tmp = 0
        left = cnt
        right = min(cnt + add, len(nums))
        for j in range(left, right):
            tmp += nums[j]
        ans = max(tmp, ans)
    print(ans)


main()


### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    S = input()
    nums = []
    now = 1
    cnt = 0
    for s in S:
        if int(s) == now:
            cnt += 1
        else:
            nums.append(cnt)
            now ^= 1
            cnt = 1
    if cnt > 0:
        nums.append(cnt)
    if len(nums) % 2 == 0:
        nums.append(0)
    add = 2 * K + 1
    ans = 0
    left = 0
    right = 0
    tmp = 0
    for cnt in range(0, len(nums), 2):
        nleft = cnt
        nright = min(cnt + add, len(nums))
        while nleft > left:
            tmp -= nums[left]
            left += 1
        while nright > right:
            tmp += nums[right]
            right += 1
        ans = max(tmp, ans)
    print(ans)


main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Fri Jun 12 21:52:40 2020

@author: naoki
"""

N = int(input()) # 並んでいる人数N

S = input() # 向いている方向
    
change = [0 for i in range(N)] # 向きを変えた回数を格納

for i in range(N):
    change[i] += S.count("W",0,i) # リーダーよりも西側にいるときに西に向いている人数をカウント
    change[i] += S.count("E",i+1,N) # リーダーよりも東側にいるときに東を向いている人数をカウント
change.sort() # 向きを変えた回数が少ない順に並べ替え
print(change[0])


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Fri Jun 12 21:52:40 2020

@author: naoki
"""

N = int(input()) # 並んでいる人数N

S = input() # 向いている方向
    
change = [0 for i in range(N)] # 向きを変えた回数を格納
change[0] = S.count("E",1,N)
for i in range(1,N):
        if S[i-1] == "W" and S[i] == "E":
            change[i] = change[i-1]
        elif S[i-1] == "W" and S[i] != "E": 
            change[i] = change[i-1] + 1
        elif S[i-1] != "W" and S[i] == "E":
            change[i] = change[i-1] - 1
        else:
            change[i] = change[i-1]
change.sort()
print(change[0])
### BUGGY CODE ###

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

for i in a:
    mainus += i
    ans_a = a[n-1] * (sum(a) - mainus )
    ans += ans_a
    n += 1

MOD = 10 ** 9 + 7
ans %= MOD

print(ans)

### FIXED CODE ###

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

MOD = 10 ** 9 + 7
s =sum(a) % MOD
ans = 0

for i in a :
    s -= i
    s %= MOD
    ans += i * s
    ans %= MOD
    
print(ans)
### BUGGY CODE ###

S=list(input())
q=int(input())
direction=1
T=['1' for j in range(10**5)]
for i in range(q):
  query=list(input().split())
  if query[0]=='1':
    direction=-1*direction
  else:
    value=-1+2*(int(query[1])-1)
    e=value*direction
    if e==-1:
      S.insert(0,query[2])
    else:
      S.append(query[2])
if direction==-1:
  for j in range(len(S)):
    T[j]=S[len(S)-j-1]
  S=T[:len(S)]
moji=''.join(S)
print(moji)

### FIXED CODE ###

t=list(input())
q=int(input())
s=[]

for i in range(q):
  query=list(input().split())
  if query[0]=='1':
    s,t=t,s
  else:
    if query[1]=='1':
      s.extend(query[2])
    else:
      t.extend(query[2])
if s==[]:
  s=t
else:
  s.reverse()
  s.extend(t)

moji=''.join(s)
print(moji)
### BUGGY CODE ###

import re
n,q = map(int, input().split())
sss = [s for s in input()]
for i in range(q):
  l,r = map(int, input().split())
  s_temp = "".join(sss[l-1:r])
  print(len(re.findall(r"AC", s_temp)))



### FIXED CODE ###

n,q = list(map(int,input().split()))
s = input()
lll = [0 for _ in range(n)]
for i in range(n-1):
  if s[i] == "A" and s[i+1] == "C":
    lll[i+1] = lll[i] + 1
  else:
    lll[i+1] = lll[i]
for i in range(q):
  l,r = list(map(int,input().split()))
  print(lll[r-1] - lll[l-1])
### BUGGY CODE ###

n = int(input())

P = [int(_) for _ in input().split()]

cnt=0
for i in range(n):
    judge=True
    for j in P[:i+1]:
        if P[i] > j:
            judge = False
    if judge==True:
        cnt +=1
print(cnt)

### FIXED CODE ###

n = int(input())

P = [int(_) for _ in input().split()]

cnt=0
a = P[0]
for i in range(n):
    a = min(a,P[i])
    if P[i] <= min(a,P[i]):
        cnt+=1
print(cnt)
### BUGGY CODE ###

def main():
    k,n=map(int,input().split())
    a=list(map(int,input().split()))
    resf=10**7
    for i in a:
        if i==a[0]:
            res=min(a[-1]-a[0],k-(a[1]-a[0]))
        elif i==a[-1]:
            res=min(k-(a[-1]-a[-2]),a[-1]-a[0])
        else:
            res=min(k-(a[a.index(i)+1]-i),k-(i-a[a.index(i)-1]))
        resf=min(resf,res)
    print(resf)

if __name__ == '__main__':
    main()

### FIXED CODE ###

# coding: utf-8
# Your code here!
def main():
    k,n=map(int,input().split())
    a=list(map(int,input().split()))
    resf=10**7
    z=0
    for i in a:
        if i==a[0]:
            res=min(a[-1]-a[0],k-(a[1]-a[0]))
        elif i==a[-1]:
            res=min(k-(a[-1]-a[-2]),a[-1]-a[0])
        else:
            if k-(a[z+1]-i)<=k-(i-a[z-1]):
                res=k-(a[z+1]-i)
            else:
                res=k-(i-a[z-1])
        if resf>=res:
            resf=res
        z+=1
    print(resf)

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

n = int(input())
v = list(sorted(map(int, input().split())))

s = set()

for i, x in list(enumerate(v))[:-2]:
    for j, y in list(enumerate(v))[i+1:-1]:
        for k, z in list(enumerate(v))[j+1:]:
            if z < x+y and (x, y, z) not in s:
                s.add((x, y, z))

print(len(s))


### FIXED CODE ###

n = int(input())
v = list(sorted(map(int, input().split())))
v.append(2000)
total = n*(n-1)*(n-2) / 6



def bs(left, s):
    right = n+1
    while left < right-1:
        m = (right+left)//2

        if v[m]>=s:
            right = m
        else:
            left = m
    return left+1






for i, x in enumerate(v[:-2]):
    for j, y in enumerate(v[i+1:-1]):
        k = bs(j+1, y+x)
        total -= (n-k)

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

import numpy as np
import itertools
H, W, K = [int(_) for _ in input().split()]
S = np.zeros((H + 1, W + 1), dtype=int)
S[1:, 1:] = [[int(_) for _ in input()] for _ in range(H)]
cum = S.cumsum(axis=0).cumsum(axis=1)
#sum(a,b -> x,y) (1-indexed)
#cum[x][y]+cum[a-1][b-1]-cum[a-1][y]-cum[x][b-1]
ans = 10**10
for bs in itertools.product([True, False], repeat=H - 1):
    bs = [True] + list(bs) + [True]
    idxs = []
    for i, b in enumerate(bs):
        if b:
            idxs += [i]
    cum2 = np.array([cum[i2] - cum[i1] for i1, i2 in zip(idxs, idxs[1:])])
    i = 0
    cnt = sum(bs) - 3
    while i < W:
        i += min(
            np.searchsorted(c[i + 1:] - c[i], K, side='right') for c in cum2)
        cnt += 1
    ans = min(ans, cnt)
print(ans)


### FIXED CODE ###

import numpy as np
import itertools
H, W, K = [int(_) for _ in input().split()]
S = np.zeros((H + 1, W + 1), dtype=int)
S[1:, 1:] = [[int(_) for _ in input()] for _ in range(H)]
cum = S.cumsum(axis=0).cumsum(axis=1)
#sum(a,b -> x,y) (1-indexed)
#cum[x][y]+cum[a-1][b-1]-cum[a-1][y]-cum[x][b-1]
ans = 10**10
for bs in itertools.product([True, False], repeat=H - 1):
    bs = [True] + list(bs) + [True]
    idxs = []
    for i, b in enumerate(bs):
        if b:
            idxs += [i]
    cum2 = np.array([cum[i2] - cum[i1] for i1, i2 in zip(idxs, idxs[1:])])
    i = 0
    cnt = sum(bs) - 3
    while i < W:
        di = min(
            np.searchsorted(c[i + 1:] - c[i], K, side='right') for c in cum2)
        if di == 0:
            cnt = 10**10
            break
        i += di
        cnt += 1
    ans = min(ans, cnt)
print(ans)
### BUGGY CODE ###

K = input()
N = len(K)
D = int(input())
mod = 10**9+7

dp = [[[0]*D for _ in range(2)] for _ in range(N+1)]
dp[0][0][0] = 1

for i in range(N):
    a = ord(K[i])-48
    for j in range(D):
        for k in range(10):
            b = (j+k)%D
            dp[i+1][1][b] += dp[i][1][j]
            if k<a:
                dp[i+1][1][b] += dp[i][0][j]
            dp[i+1][1][b] %= mod
    
    for j in range(D):
        b = (j+a)%D
        dp[i+1][0][b] += dp[i][0][j]
        dp[i+1][0][b] %= mod

print((dp[N][1][0]+dp[N][0][0]-1)%mod)

### FIXED CODE ###

K = input()
N = len(K)
D = int(input())
mod = 10**9+7

dp = [[[0]*D for _ in range(2)] for _ in range(N+1)]
dp[0][1][0] = 0
dp[0][0][0] = 1

for i in range(N):
    a = ord(K[i])-48
    
    for j in range(D):
        for k in range(10):
            dp[i+1][1][(j+k)%D] += dp[i][1][j]
            dp[i+1][1][(j+k)%D] %= mod

    for j in range(D):
        dp[i+1][0][(j+a)%D] += dp[i][0][j]
        dp[i+1][0][(j+a)%D] %= mod

    for j in range(D):
        for k in range(a):
            dp[i+1][1][(j+k)%D] += dp[i][0][j]
            dp[i+1][1][(j+k)%D] %= mod

print((dp[N][1][0] + dp[N][0][0]-1)%mod)
### BUGGY CODE ###

import bisect
import math

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

a.sort()

ans = sum(a)
for i in range(m):
    tmp = a.pop()
    ans -= tmp
    cost = math.floor(tmp/2)
    ans += cost
    idx = bisect.bisect_left(a,cost)
    a.insert(idx,cost)

print(ans)


### FIXED CODE ###

import bisect
import math

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

a.sort()

ans = sum(a)
for i in range(m):
    tmp = a.pop()
    ans -= tmp
    cost = math.floor(tmp/2)
    ans += cost
    idx = bisect.bisect_left(a,cost)
    a.insert(idx,cost)

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

# https://atcoder.jp/contests/abc122/tasks/abc122_c
import numpy as np

N, Q = map(int, input().split())
N = int(N)
S = input()
lr = []
for _ in range(Q):
    l, r = map(int, input().split())
    lr.append((l - 1, r - 1))

t = []
for i in range(1, len(S) + 1):
    subset = S[:i]
    t.append(subset.count('AC'))
for l, r in lr:
    print(t[r] - t[l])


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
cnt = [0]
for i in range(2, len(S) + 1):
    if S[i - 2:i] == 'AC':
        v = cnt[-1] + 1
    else:
        v = cnt[-1]
    cnt.append(v)

# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

S = input().strip()
Q = int(input())

reverse = False

for _ in range(Q):
    s = input().strip()
    if s.startswith("1"):
        reverse = not reverse
    else:
        _, f, c = s.split()
        if f == "1":
            if reverse:
                S = S + c
            else:
                S = c + S
        else:
            if reverse:
                S = c + S
            else:
                S = S + c

if reverse:
    print(S[::-1])
else:
    print(S)


### FIXED CODE ###

import sys
input = sys.stdin.readline

S = input().strip()
Q = int(input())

reverse = False

before = ""
after = ""

for _ in range(Q):
    s = input().strip()
    if s[0] == "1":
        reverse = not reverse
    else:
        _, f, c = s.split()
        if f == "1":
            if reverse:
                after = after + c
            else:
                before = c + before
        else:
            if reverse:
                before = c + before
            else:
                after = after + c

if reverse:
    print(after[::-1] + S[::-1] + before[::-1])
else:
    print(before + S + after)
### BUGGY CODE ###

import sys
n = int(input())
h = list(map(int, input().split()))

max = 0
flag = bool(0)
for i in range(n - 1):
    flag = bool(0)
    count = 0
    for j in range(i, n - 1):
        if h[j] >= h[j + 1]:
            count += 1
            if count > max:
                max = count
        else:
            if max > n / 2:
                sys.exit()
            else:
                break

print(max)


### FIXED CODE ###

import sys
n = int(input())
h = list(map(int, input().split()))

max = 0
max_i = 0
count = 0
for i in range(n - 1):
    if h[i] >= h[i + 1]:
        count += 1
        if count > max:
            max = count
    else:
        count = 0

print(max)
### BUGGY CODE ###

def popcount(n):
	res=0
	while n > 0:
		res += n % 2;
		n //= 2
	return res
n=0
def init_seg(_n):
	global n
	n = 1
	while n < _n:
		n *= 2
MAX_N=262144
data=[0]*MAX_N
datb=[0]*MAX_N

def add(a, b, x, k, l, r):
	if a <=l and r <= b:
		data[k] += x
	elif l < b and a < r:
		datb[k] += (min(b,r) - max(a,l))*x
		add(a, b, x, 2 * k + 1, l, (l + r) / 2)
		add(a, b, x, 2 * k + 2, (l + r) / 2, r)

def sum(a, b, k, l, r):
	if b <=l or r <= a:
		return 0
	elif a <= l and r <= b:
		return data[k] * (r - l) + datb[k]
	else:
		res = (min(b, r) - max(a, l)) * data[k]
		res += sum(a, b, 2 * k + 1, l, (l + r) / 2)
		res += sum(a, b, 2 * k + 2, (l + r) / 2, r)
		return int(res)

def main():
	init_seg(int(1e5))
	global n
	for i in range(n):
		add(i, i + 1, 0, 0, 0, n)

	N,C=map(int,input().split())
	for i in range(N):
		s,t,c=map(int,input().split())
		add(s, t, 2**(c-1), 0, 0, n)

	res=0
	for i in range(1,int(1e5)):
		prev=sum(i - 1, i, 0, 0, n)
		curr=sum(i, i+1, 0, 0, n)
		if prev == curr:
			res = max(res, popcount(curr))
		else:
			res = max(res, popcount(curr | prev))

	print(res)

if __name__ == '__main__':
	main()



### FIXED CODE ###

N,C=map(int,input().split())
f=[[0]*int(1e5) for _ in range(C)]

for i in range(N):
	s,t,c=map(int,input().split())
	f[c-1][s-1:t]=[1]*(t-s+1)

print(max(map(sum,zip(*f))))
### BUGGY CODE ###

import heapq
n,k = map(int,input().split())
c = []
heapq.heapify(c)
for i in range(n):
    a,b = map(int,input().split())
    c+=([a]*b)
    heapq.heapify(c)
l = heapq.nsmallest(k,c)
print(l[-1])


### FIXED CODE ###

import heapq
n,k = map(int,input().split())
d = {}
z = []
for i in range(n):
    a,b = map(int,input().split())
    z.append([a,b])
    d[a] = 0
for i in range(len(z)):
    d[z[i][0]]+=z[i][1]
c = sorted(d.keys())
l=0
for i in range(len(c)):
    if(k<=0):
        print(c[i-1])
        l+=1
        break
    k-=d[c[i]]
if(l!=1):
    print(c[-1])
### BUGGY CODE ###

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

for i in range(M):
    Bi, Ci = map(int, input().split())
    A.extend([Ci] * Bi)

print(sum(sorted(A, reverse=True)[:N]))

### FIXED CODE ###

N, M = map(int, input().split())
A = map(int, input().split())
card = {}
for a in A:
    if a not in card:
        card[a] = 1
    else:
        card[a] += 1

for i in range(M):
    Bi, Ci = map(int, input().split())
    if Ci not in card:
        card[Ci] = Bi
    else:
        card[Ci] += Bi

total = 0
count = 0
for num in sorted(card.keys(), reverse=True):
    if count + card[num] <= N:
        count += card[num]
        total += num * card[num]
    else:
        added = N - count
        count += added
        total += added * num
        break
print(total)
### BUGGY CODE ###

import bisect


def main():
  x = [int(input()) for _ in range(int(input()))]
  c = [x[-1]]

  for i in range(len(x) - 2, -1, -1):
    j = bisect.bisect(c, x[i])

    if j == len(c):
      c.append(x[i])
    else:
      c = c[:j] + c[j + 1:]
      bisect.insort(c, x[i])

  print(len(c))


if __name__ == '__main__':
  main()


### FIXED CODE ###

import bisect


def main():
  x = [int(input()) for _ in range(int(input()))]
  c = [x[-1]]

  for i in range(len(x) - 2, -1, -1):
    j = bisect.bisect(c, x[i])

    if j == len(c):
      c.append(x[i])
    else:
      c[j] = x[i]

  print(len(c))


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

from collections import deque
import sys 
sys.setrecursionlimit(10**5)
n, m = map(int, input().split())
adjacent_list = [[] for i in range(n+1)]
not_root = set()
for i in range(m):
    x, y = map(int, input().split())
    not_root.add(y)
    adjacent_list[x].append(y)
root_cand = set(list(range(1, n+1))) - not_root
root_cand = deque(root_cand)
dp = [0] * (n+1)
def dfs(node, count):
    dp[node] = max(dp[node], count + 1)
    if len(adjacent_list[node]) != 0:
        for i in adjacent_list[node]:
            if dp[i] <= dp[node]:
                dfs(i, dp[node])
while len(root_cand) != 0:
    root = root_cand.pop()
    dfs(root, -1)
print(max(dp))


### FIXED CODE ###

from collections import deque
import sys 
input = sys.stdin.readline
sys.setrecursionlimit(10**5)
n, m = map(int, input().split())
adjacent_list = [[] for i in range(n+1)]
not_root = set()
for i in range(m):
    x, y = map(int, input().split())
    not_root.add(y)
    adjacent_list[x].append(y)
dp = [-1 for i in range(n+1)]
def cul(x):
    if dp[x] != -1:
        return dp[x]
    else:
        if len(adjacent_list[x]) == 0:
            return 0
        dp[x] = max([cul(i) + 1 for i in adjacent_list[x]])
        return dp[x]
for i in range(1,n+1):
    cul(i)
print(max(dp))
### BUGGY CODE ###

n = int(input())

ab = []
ba = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))
    ba.append((b, a))

ab.sort(key=lambda x:x[0])
ba.sort(key=lambda x:x[0])

ans = 0
for i in range(n):
    if i % 2 == 0:
        if ab[0][0] == ab[-1][0]:
            b, a = ba.pop()
            ab.remove((a, b))
        else:
            a, b = ab.pop()
            ba.remove((b, a))
        ans += a
    else:
        if ba[0][0] == ba[-1][0]:
            a, b = ab.pop()
            ba.remove((b, a))
        else:
            b, a = ba.pop()
            ab.remove((a, b))
        ans -= b
print(ans)


### FIXED CODE ###

n = int(input())

ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append((a+b, a, b))

ab.sort(key= lambda x:x[0])

ans = 0
for i in range(n):
    v, a, b = ab.pop()
    if i % 2 == 0:
        ans += a
    else:
        ans -= b

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

n, k, *a = map(int, open(0).read().split())
a.sort()
mn = 1e18
for i in range(n-k+1):
    tmp = 0
    for j in range(k-1): tmp+=abs(a[i+j]-a[i+j+1])
    mn = min(mn, tmp)
print(mn)

### FIXED CODE ###

n, k, *a = map(int, open(0).read().split())
a.sort()
for i in range(n-1): a[n-i-1] = abs(a[n-i-1]-a[n-i-2])
a[0] = 0
for i in range(n-1): a[i+1] += a[i]

mn = 1e18
for i in range(n-k+1): mn = min(mn, a[i+k-1]-a[i])
print(mn)
### BUGGY CODE ###

s = list(input())
t = list(input())

def restr2(s, t):
    if len(set(s)) != len(set(t)):
        return False
    for i in range(len(s)):
        for j in range(i+1, len(s)):
            if s[i] == s[j]:
                if t[i] != t[j]:
                    return False
    return True

print('Yes' if restr2(s, t) else 'No')


### FIXED CODE ###

from collections import defaultdict

def a(s):
    dic = defaultdict(list)
    for i, ch in enumerate(s):
        dic[ch].append(i)
    return sorted(list(dic.values()))

s = input()
t = input()
print('Yes' if a(s) == a(t) else 'No')