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

import sys
import itertools
import collections


def search(H, W, S, start, end):
    wall_i = ord(b'#')
    used = [[-1 for h in range(W)] for w in range(H)]

    qu = collections.deque()
    qu.append(start)
    used[start[0]][start[1]] = 0

    while qu:
        h, w = qu.popleft()
        cost = used[h][w]
        for h0, w0 in ((h - 1, w), (h + 1, w), (h, w - 1), (h, w + 1)):
            if not (0 <= h0 < H and 0 <= w0 < W):
                continue
            if used[h0][w0] != -1:
                continue
            if S[h0][w0] == wall_i:
                continue

            if (h0, w0) == end:
                return cost + 1
            used[h0][w0] = cost + 1
            qu.append((h0, w0))
        cost += 1

    return -1


def resolve(in_):
    H, W = map(int, next(in_).split())
    S = tuple(s.strip() for s in itertools.islice(in_, H))

    road_i = ord(b'.')

    roads = []
    for h in range(H):
        for w in range(W):
            if S[h][w] == road_i:
                roads.append((h, w))
    
    ans = max(search(H, W, S, start, end) for start, end in itertools.permutations(roads, 2))
    
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import itertools
import collections


def search(H, W, S, start):
    wall_i = ord(b'#')
    used = [[-1 for h in range(W)] for w in range(H)]

    qu = collections.deque()
    qu.append(start)
    used[start[0]][start[1]] = 0

    while qu:
        h, w = qu.popleft()
        cost = used[h][w]
        for h0, w0 in ((h - 1, w), (h + 1, w), (h, w - 1), (h, w + 1)):
            if not (0 <= h0 < H and 0 <= w0 < W):
                continue
            if used[h0][w0] != -1:
                continue
            if S[h0][w0] == wall_i:
                continue

            used[h0][w0] = cost + 1
            qu.append((h0, w0))

    return max(cost for costs in used for cost in costs)


def resolve(in_):
    H, W = map(int, next(in_).split())
    S = tuple(s.strip() for s in itertools.islice(in_, H))

    road_i = ord(b'.')

    roads = []
    for h in range(H):
        for w in range(W):
            if S[h][w] == road_i:
                roads.append((h, w))
    
    ans = max(search(H, W, S, start) for start in roads)
    
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


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

import numpy as np

abcs = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
anum = 0

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

for i in range(N-1):
    for j in range(i+1,N):
        c1 = np.zeros(26)
        c2 = np.zeros(26)
        for k in range(26):
            for l in range(10):
                if abcs[k] == strings[i][l]:
                    c1[k] += 1
                if abcs[k] == strings[j][l]:
                    c2[k] += 1
        if sum(c1 == c2) == 26:
            anum +=1

print(anum)


### FIXED CODE ###

N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
dict = {}
ans = 0

for i in s:
    if i in dict:
        ans += dict[i]
        dict[i] += 1
    else:
        dict[i] = 1

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

from itertools import permutations
N, M, R = map(int, input().split())
r = map(int, input().split())
inf = float('inf')
d = [[inf] * N for i in range(N)]

for i in range(N):
    d[i][i] = 0

for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    t = min(c, d[a][b])
    if d[a][b] > c:
        d[a][b], d[b][a] = t, t


for i in range(N):
    for j in range(N):
        for k in range(N):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])


ans = inf
for i in permutations(r):
    temp = 0
    for j in range(len(i)-1):
        temp += d[i[j]-1][i[j+1]-1]
        if temp > ans:
            break
    ans = min(ans, temp)

print(ans)

### FIXED CODE ###

from itertools import permutations

def main():
    N, M, R = map(int, input().split())
    r = map(int, input().split())
    inf = float('inf')
    d = [[inf] * N for i in range(N)]

    for i in range(N):
        d[i][i] = 0

    for i in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        if d[a][b] > c:
            d[a][b], d[b][a] = c, c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                temp = d[i][k] + d[k][j]
                if d[i][j] > temp:
                    d[i][j] = temp

    ans = inf
    for i in permutations(r):
        temp = 0
        for j in range(len(i)-1):
            temp += d[i[j] - 1][i[j + 1] - 1]
            if temp > ans:
                break
        if ans > temp:
            ans = temp

    print(ans)


main()
### BUGGY CODE ###

def main():
    from fractions import gcd

    MOD = 10 ** 9 + 7

    N = int(input())

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

    B = [1] * (N + 1)

    for index, a in enumerate(A):
        tmp = gcd(B[index], a)
        B[index + 1] = B[index] * a // tmp

    C = [1] * (N + 1)
    for i in range(N - 1, -1, -1):
        tmp =gcd(C[i + 1], A[i])
        C[i] = C[i + 1] * A[i] // tmp

    # print (B)
    # print (C)

    ans = 0
    for i in range(N):
        tmp1 = gcd(B[i], C[i + 1])
        tmp2 = B[i] * C[i + 1] // tmp1

        tmp3 = gcd(tmp2, A[i])
        tmp4 = tmp2 * A[i] // tmp3

        ans += (tmp4 // A[i] % MOD)
        ans %= MOD

        # print (ans)

    print (ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    from fractions import gcd

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

    MOD = 10 ** 9 + 7

    tmp = 1
    for a in A:
        tmp *= a // gcd(tmp, a)

    ans = 0
    for a in A:
        ans += tmp // a
    ans %= MOD

    print (ans)

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

def main():
    K = int(input())

    if K % 2 == 0:
        return -1
    elif K % 5 == 0:
        return -1

    an = ""

    while True:
        an = an + "7"

        if int(an)%K == 0:
            return len(an)

if __name__ == "__main__":
    answer = main()
    print(answer)

### FIXED CODE ###

def main():
    K = int(input())

    if K % 2 == 0:
        return -1
    elif K % 5 == 0:
        return -1

    an = 7
    counter = 1

    while True:
        modan = an % K

        if modan == 0:
            return counter

        an = modan * 10 + 7
        counter = counter + 1

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

n = int(input())
li = []
for i in range(n):
    li.append(input())
li.sort()
tmp = list(sorted(set(li), key=li.index))
oplist = [[0 for i in range(2)] for j in range(len(tmp))]
for i in range(len(tmp)):
    oplist[i][1] = tmp[i]
cnt = 0
for i in range(len(oplist)):
    if cnt < li.count(oplist[i][1]):
        cnt = li.count(oplist[i][1])
    oplist[i][0] = li.count(oplist[i][1])
for i in range(len(tmp)):
    if oplist[i][0] == cnt:
        print(oplist[i][1])



### FIXED CODE ###

import math
import sys
n = int(input())
li=[input()]
for i in range(n-1):
    li.append(input())
li.sort()
cnt = 0
tmp = 1
li.append('')
for i in range(n):
    if (li[i] == li[i + 1]):
        tmp += 1
    else:
        if(cnt<tmp):
            cnt=tmp
        tmp = 1
tmp=1
for i in range(n):
    if (li[i] == li[i + 1]):
        tmp += 1
    else:
        if (cnt == tmp):
                print(li[i])
        tmp = 1
### BUGGY CODE ###

N, X, Y = map(int, input().split())
minus = []
plus = []
for A in range(1,N):
    for B in range(A+1,N+1):
        if B - A > abs(X -A) + abs(Y - B) + 1:
            minus.append(B-A)
            plus.append(abs(X -A) + abs(Y - B) + 1)
for k in range(1,N):
    print(N - k - minus.count(k) + plus.count(k))

### FIXED CODE ###

N, X, Y = map(int, input().split())
ks = [0]*(N-1)
for A in range(1,N):
    for B in range(A+1,N+1):
        if B - A > abs(X -A) + abs(Y - B) + 1:
            ks[B-A-1] -= 1
            ks[abs(X -A) + abs(Y - B)] += 1
for k in range(1,N):
    print(N - k + ks[k-1])
### BUGGY CODE ###

from collections import Counter
n = int(input())
count =0
store_list=[]
ans_list=[1]*n
for _ in range(n):
    s = input()
    dict_s =Counter(s)
    #print(dict_s)
    if dict_s in store_list:
        a = store_list.index(dict_s)
        ans_list[a] += 1
    else:
        store_list.append(dict_s)
#print(sum(ans_list))
#print(ans_list)
sum = 0
for i in range(n):
    b = ans_list[i]
    sum += b*(b-1)/2
       
print(int(sum))

### FIXED CODE ###

n = int(input())
count =0
store_list=[]
dictA={}
ans_list=[1]*n
for _ in range(n):
    s = input()
    s_list = list(s)
    s_list.sort()
    a =tuple(s_list)
    dictA.setdefault(a,0)
    dictA[a] +=1 
    #print(dictA)
#print(sum(ans_list))
total = 0
for value in dictA.values() :
    total += value*(value-1)/2
       
print(int(total))
### BUGGY CODE ###

x = int(input())

flag = False

for i in range(int(pow(x, 1/5))+1):
    a = x - i**5
    for j in range(a+1):
        if j**5 == a:
            flag = True
            break
    if flag:
        print(j, -i)
        break


### FIXED CODE ###

x = int(input())

div = set()
for i in range(1, int(x**0.5)+1):
    if x % i == 0:
        div.add(i)
        div.add(x//i)

div = list(div)

for d in div:
    for a in range(int(pow(x, 1/2))+1):
        b = a - d
        if a**5 - b**5 == x:
            print(a, b)
            break
### BUGGY CODE ###

N = int(input())
S = input()
S = [(a, p) for p, a in enumerate(S)]
count = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i][0] != S[j][0]:
            for k in range(j+1,N):
                if S[i][0] != S[k][0] and S[j][0] != S[k][0] and j-i != k-j:
                    count+=1
print(count) 

### FIXED CODE ###

N = int(input())
S = list(input())
count = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for j in range(i+1,N):
        if 2*j-i < N:
            if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
                count-=1
print(count)
### BUGGY CODE ###

import sys


def main():
    input = sys.stdin.readline

    n = int(input())
    items = [tuple(map(int, input().split())) for _ in range(n)]

    L_MAX = 10**5
    D_TH = 8
    V_MAX = 1 << D_TH
    dp = [[0] * (L_MAX + 1) for _ in range(V_MAX + 1)]

    for i, (val, w) in enumerate(items[:V_MAX]):
        for j in range(L_MAX + 1):
            i1 = i + 1
            i0 = (i + 1) // 2
            if j < w:
                dp[i1][j] = dp[i0][j]
            else:
                dp[i1][j] = max(dp[i0][j], dp[i0][j - w] + val)

    q = int(input())
    for _ in range(q):
        v, l = map(int, input().split())
        v -= 1

        if v < V_MAX:
            ans = dp[v + 1][l]
        else:
            items_sub = [items[v]]
            while v >= V_MAX:
                v = (v - 1) // 2
                items_sub.append(items[v])

            ans = 0
            for bit in range(1 << len(items_sub)):
                s_val = s_w = 0
                for i, (val, w) in enumerate(items_sub):
                    if (bit >> i) & 1:
                        s_val += val
                        s_w += w
                if s_w <= l:
                    ans = max(ans, dp[v + 1][l - s_w] + s_val)

        print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline

    n = int(input())

    L_MAX = 10**5
    D_TH = 10
    V_MAX = (1 << D_TH) - 1
    dp = [[0] * (L_MAX + 1)]
    # items = []
    items_v = []
    items_w = []

    for i in range(n):
        val, w = map(int, input().split())
        if i < V_MAX:
            i1 = i + 1
            i0 = (i + 1) >> 1
            dp_ = dp[i0][:]

            # for j in range(w):
            #     dp[i1][j] = dp[i0][j]
            for j in range(w, L_MAX + 1)[::-1]:
                if dp_[j] < dp_[j - w] + val:
                    dp_[j] = dp_[j - w] + val
            dp.append(dp_)
        else:
            # items.append((val, w))
            items_v.append(val)
            items_w.append(w)

    # items = tuple(items)

    q = int(input())
    for _ in range(q):
        v, l = map(int, input().split())
        v -= 1

        if v < V_MAX:
            ans = dp[v + 1][l]
        else:
            vv = []
            ww = []
            while v >= V_MAX:
                # vv.append(items[v - V_MAX][0])
                # ww.append(items[v - V_MAX][1])
                vv.append(items_v[v - V_MAX])
                ww.append(items_w[v - V_MAX])
                v = (v - 1) >> 1

            ans = dp[v + 1][l]
            # m = len(vv)
            m2 = 1 << len(vv)
            v_sub = [0] * m2
            w_sub = [0] * m2
            for bit in range(1, m2):
                bit_min = bit & (-bit)
                x = bit_min.bit_length() - 1

                s_w = w_sub[bit - bit_min] + ww[x]
                w_sub[bit] = s_w
                if s_w <= l:
                    s_val = v_sub[bit - bit_min] + vv[x]
                    v_sub[bit] = s_val
                    ans = max(ans, dp[v + 1][l - s_w] + s_val)

        print(ans)


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

from collections import deque
import bisect

a, b, q = [int(x) for x in input().split()]
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]
#x = [int(input()) for i in range(q)]

s_que = deque(s)
s_que.appendleft(-10 ** 12)
s_que.append(10 ** 12)

t_que = deque(t)
t_que.appendleft(-10 ** 12)
t_que.append(10 ** 12)

for i in range(q):
    x = int(input())
    k = bisect.bisect_left(s_que, x)
    sb = s_que[k]
    sa = s_que[k-1]
    j = bisect.bisect_left(t_que, x)
    tb = t_que[j]
    ta = t_que[j-1]

    y = []
    for h in [sa, sb]:
        for g in [ta, tb]:
            y.append(abs(x-h) + abs(h-g))
    for h in [ta, tb]:
        for g in [sa, sb]:
            y.append(abs(x-h) + abs(h-g))

    print(min(y))


### FIXED CODE ###

#from collections import deque
import bisect

a, b, q = [int(x) for x in input().split()]
s = [-10**12] + [int(input()) for i in range(a)] + [10**12]
t = [-10**12] + [int(input()) for i in range(b)] + [10**12]
#x = [int(input()) for i in range(q)]

#s_que = deque(s)
#s_que.appendleft(-10 ** 12)
#s_que.append(10 ** 12)

#t_que = deque(t)
#t_que.appendleft(-10 ** 12)
#t_que.append(10 ** 12)

for i in range(q):
    x = int(input())
    k = bisect.bisect_left(s, x)
    sb = s[k]
    sa = s[k-1]
    j = bisect.bisect_left(t, x)
    tb = t[j]
    ta = t[j-1]

    y = []
    for h in [sa, sb]:
        for g in [ta, tb]:
            y.append(abs(x-h) + abs(h-g))
    for h in [ta, tb]:
        for g in [sa, sb]:
            y.append(abs(x-h) + abs(h-g))

    print(min(y))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

_max_sum = 0
point = 0
for i in range(n-k+1):
    _sum = sum(p[i:i+k])
    if _sum >= _max_sum:
        _max_sum = _sum
        point = i

expected = 0
for i in p[point:point+k]:
    expected += 1 + 0.5 * (i - 1)
print(expected)


### FIXED CODE ###

import sys
input = sys.stdin.readline

n, k = [int(i) for i in input().split()]
p = [0] * n
for i,v in enumerate(input().split()):
    p[i] = 1.0 + 0.5 * (float(v) - 1.0)

_max_sum = 0
_prev_sum = 0
for i in range(0, n-k+1):
    if i == 0:
        _sum = sum(p[:k])
    else:
        _sum = _prev_sum - p[i-1] + p[i+k-1]
    if _sum >= _max_sum:
        _max_sum = _sum
    _prev_sum = _sum
print(_max_sum)
### BUGGY CODE ###

from collections import defaultdict
def main():
    n = int(input())
    a = list(map(int, input().split(" ")))
    d = defaultdict(lambda:0)
    d2 = {}
    for i in a:
        d[i] += 1
    for i,j in d.items():
        x = j*(j-1)//2
        d2[i] = x
    ans = 0
    for i,j in d.items():
        ans = sum(d2.values())
    for i in range(n):
        print(ans-d[a[i]]+1)

if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import defaultdict
def main():
    n = int(input())
    a = list(map(int, input().split(" ")))
    d = defaultdict(lambda:0)
    d2 = {}
    for i in a:
        d[i] += 1
    for i,j in d.items():
        x = j*(j-1)//2
        d2[i] = x
    ans = 0
    ans = sum(d2.values())
    for i in range(n):
        print(ans-d[a[i]]+1)

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

n,m = map(int,input().split())
x = list(map(int,input().split()))
if n>=m:
  print(0)
else:
  x.sort()
  dx = []
  for i in range(m-1):
    dx.append(abs(x[i]-x[i+1]))
  for i in range(n-1):
    dx.remove(max(dx))
  print(sum(dx))

### FIXED CODE ###

n,m = map(int,input().split())
x = list(map(int,input().split()))
if n>=m:
  print(0)
else:
  x.sort()
  dx = []
  for i in range(m-1):
    dx.append(abs(x[i]-x[i+1]))
  dx.sort()
  print(sum(dx[:m-n]))
### BUGGY CODE ###

# Handstand 2
# c_ij = {1<=k<=N : 先頭の桁がiで、末尾の桁の数がjであるもの}

N = int(input())
count = 0

# 先頭の桁をi, 末尾の桁をjとする数の数を求める
def c(i, j):
    count_num = 0
    for a in range(1,N+1):
        a_str = str(a)
        a_i, a_j = int(a_str[0]), int(a_str[-1]) # 各数の先頭桁を求める
        if i==a_i and j==a_j:
            count_num = count_num + 1
    return count_num


for i in range(10):
    for j in range(10):
        count += c(i,j)*c(j,i)

print(count)


### FIXED CODE ###

# Handstand 2

N = int(input())
count = 0

count_list = [[0]*10 for i in range(10)]

# 1~Nまでの先頭iと末尾jの頻度を全て算出する
for a in range(1,N+1):
    a_str = str(a)
    a_i, a_j = int(a_str[0]), int(a_str[-1]) # 各数の先頭桁を求める
    count_list[a_i][a_j] = count_list[a_i][a_j] + 1

# count_listから全ての組み合わせ数を計算
for i in range(1,10):
    for j in range(1,10):
        count = count + count_list[i][j]*count_list[j][i]

print(count)
### BUGGY CODE ###

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

ans = 0
for i in range(n)[-1::-1]:
    val = B[i] - A[i]%B[i]
    if val == B[i]:
        continue
    ans += val
    j = 0
    while j != i:
        A[j] += val
        j += 1
print(ans)

### FIXED CODE ###

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

ans = 0
for i in range(n)[-1::-1]:
    val = B[i] - (A[i] + ans)%B[i]
    if val == B[i]:
        continue
    ans += val
    
print(ans)
### BUGGY CODE ###

def main():
    from itertools import product

    n, s = int(input()), tuple(input())
    m = {'R', 'G', 'B'} 
    ans = 0

    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            if s[i] == s[j]:
                continue
            t = m - {s[i], s[j]}
            t = t.pop()
            d = j - i
            ans += s[j + 1:].count(t)
            if j + d < n and s[j + d] == t:
                ans -= 1

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, s = int(input()), input()
    r, g, b = s.count('R'), s.count('G'), s.count('B')
    ans = r * g * b
    v = {'R', 'G', 'B'}
    for i in range(n - 2):
        for j in range(n // 2 + 1):
            if i + j + j < n:
                if v == {s[i], s[i + j], s[i + j + j]}:
                    ans -= 1
    print(ans)


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

# import sys; input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**7)
# from collections import defaultdict
ALPHABET_SIZE = 26

def getlist():
	return list(map(int, input().split()))

class Node(object):
	def __init__(self, char, ALPHABET_SIZE):
		self.char = char
		self.children = [-1] * ALPHABET_SIZE
		self.flag = [0] * ALPHABET_SIZE

class Trie(object):
	def __init__(self):
		self.root = Node(' ', ALPHABET_SIZE)

	def _convert_char_to_num(self, char):
		return ord(char) - ord('a')

	def insert(self, word, tail):
		res = 0 #合う値
		current = self.root
		currentFlag = [0] * ALPHABET_SIZE

		for char in word:
			char_index = self._convert_char_to_num(char)
			for i in range(ALPHABET_SIZE):
				currentFlag[i] += current.flag[i]
			res += currentFlag[char_index]
			currentFlag[char_index] = 0

			if current.children[char_index] != -1:
				current = current.children[char_index]

			else:
				new_node = Node(char, ALPHABET_SIZE)
				current.children[char_index] = new_node
				current = new_node

		char_index = self._convert_char_to_num(tail)
		res += currentFlag[char_index]

		current.flag[self._convert_char_to_num(tail)] += 1

		return res

#処理内容
def main():
	N = int(input())
	L = []
	for i in range(N):
		S = input()[::-1]
		L.append([len(S), S])

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

	ans = 0
	trie = Trie()
	for val, s in L:
		s1 = s[:-1]
		tail = s[-1]
		ans += trie.insert(s1, tail)
		# print(ans)

	print(ans)

if __name__ == '__main__':
	main()


### FIXED CODE ###

# import sys; input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**7)
# from collections import defaultdict
ALPHABET_SIZE = 26

def getlist():
	return list(map(int, input().split()))

class Node(object):
	def __init__(self, char):
		self.char = char
		self.children = {}
		self.flag = [0] * ALPHABET_SIZE

class Trie(object):
	def __init__(self):
		self.root = Node(' ')

	def _convert_char_to_num(self, char):
		return ord(char) - 97

	def insert(self, word, tail):
		res = 0 #合う値
		current = self.root
		currentFlag = [0] * ALPHABET_SIZE

		for char in word:
			char_index = self._convert_char_to_num(char)
			for i in range(ALPHABET_SIZE):
				currentFlag[i] += current.flag[i]
			res += currentFlag[char_index]
			currentFlag[char_index] = 0

			if char_index in current.children:
				current = current.children[char_index]

			# if current.children[char_index] != -1:
			# 	current = current.children[char_index]
			else:
				new_node = Node(char)
				current.children[char_index] = new_node
				current = new_node

		char_index = self._convert_char_to_num(tail)
		res += currentFlag[char_index]

		current.flag[self._convert_char_to_num(tail)] += 1

		return res

#処理内容
def main():
	N = int(input())
	L = []
	for i in range(N):
		S = input()[::-1]
		L.append([len(S), S])

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

	ans = 0
	trie = Trie()
	for val, s in L:
		s1 = s[:-1]
		tail = s[-1]
		ans += trie.insert(s1, tail)
		# print(ans)

	print(ans)

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

s = input()
t = input()
import string
for i in range(len(s)):
    if s[i:i+1] != t[i:i+1]:
        s = s.translate(str.maketrans(s[i:i+1]+t[i:i+1],t[i:i+1]+s[i:i+1]))
if s == t:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

s = input()
t = input()
        
dic = "abcdefghijklmnopqrstuvwxyz"
s_dic = {}
t_dic = {}
for i in dic:
    s_dic[i] = []
    t_dic[i] = []

for i in range(len(s)):
    s_dic[s[i:i+1]].append(i)
    t_dic[t[i:i+1]].append(i)

s_list = s_dic.values()
t_list = t_dic.values()

if sorted(s_list) == sorted(t_list):
    print("Yes")
else:
    print("No")