Problem:


Score : 300 points

Problem Statement

You are given strings S and T consisting of lowercase English letters.

You can perform the following operation on S any number of times:

Operation: Choose two distinct lowercase English letters c_1 and c_2, then replace every occurrence of c_1 with c_2, and every occurrence of c_2 with c_1.

Determine if S and T can be made equal by performing the operation zero or more times.

Constraints

1 \leq |S| \leq 2 \times 10^5

|S| = |T|

S and T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T

Output

If S and T can be made equal, print Yes; otherwise, print No.

Sample Input 1

azzel
apple

Sample Output 1

Yes

azzel can be changed to apple, as follows:

Choose e as c_1 and l as c_2. azzel becomes azzle.

Choose z as c_1 and p as c_2. azzle becomes apple.

Sample Input 2

chokudai
redcoder

Sample Output 2

No

No sequences of operation can change chokudai to redcoder.

Sample Input 3

abcdefghijklmnopqrstuvwxyz
ibyhqfrekavclxjstdwgpzmonu

Sample Output 3

Yes



Sample input:
azzel
apple


Sample output:
Yes

Submission status: Time Limit Exceeded

Solution code:
S=input()
T=input()

for i in range(len(S)):
    s=S[i]
    t=T[i]
    Stemp=S
    if s!=t:
        S=S.replace(s,"1")
        if t in Stemp:
            S=S.replace(t,s)
        S=S.replace("1",t)

if S==T:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
s=input()
t=input()
n=len(s)

for i in range(n):
    a=s[i]
    b=t[i]
    s=s.translate(str.maketrans({a:b,b:a}))
    
    
if(s==t):print("Yes")
else:print("No")

Submission status: Time Limit Exceeded

Solution code:
S = input()
T = input()
for i in range(len(S)):
    if S[i] != T[i]:
        s = S[i]
        t = T[i]
        T= T.replace(s,'1',10**6)
        T= T.replace(t,'2',10**6)
        T=T.replace('2',s,10**6)
        T=T.replace('1',t,10**6)
if S ==T:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
S = [str(i) for i in input()]
T = [str(i) for i in input()]
ans = "Yes"

for j in range(len(S)):
    IDXs = [i for i, x in enumerate(S) if x == S[j]]
    IDXt = [i for i, x in enumerate(T) if x == T[j]]

    if IDXs != IDXt:
        ans = "No"
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

S = input()
T = input()

AS = defaultdict(list)
AT = defaultdict(list)

isok = True
for i in range(len(S)):
    AS[S[i]].append(i)
    AT[T[i]].append(i)
    if AS[S[i]]!=AT[T[i]]:
        isok = False
        break
        
if isok:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
s = input().strip()
t = input().strip()

for i in range(len(s)):
    if s[i] != t[i]:
        s = s.translate(str.maketrans({s[i]:t[i], t[i]:s[i]}))

if s == t:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

S = input()
T = input()

AS = defaultdict(list)
AT = defaultdict(list)

for i in range(len(S)):
    AS[S[i]].append(i)
    AT[T[i]].append(i)
    
isok = True
for i in range(len(S)):
    if AS[S[i]]!=AT[T[i]]:
        isok = False
        break
        
if isok:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
s = input()
t = input()

[globals().update({'s': s.translate(str.maketrans(s[i] + t[i], t[i] + s[i]))}) for i in range(len(s)) if not s[i] == t[i]]
print("Yes" if s == t else "No")

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    S = input()
    T = input()

    for i in range(len(S)):
        if S[i] == T[i]:
            continue

        for j in range(i - 1, -1, -1):
            if T[i] == T[j] and S[i] != S[j]:
                print("No")
                return

            if S[i] == S[j] and T[i] != T[j]:
                print("No")
                return

    print("Yes")




main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
t = input()

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
t = input()

for i in range(len(s)):
  if s[i] == t[i]:
    continue
  else:
    tmp = s[i]
    s = s.replace(t[i],'X')
    s = s.replace(s[i],t[i])
    s = s.replace('X',tmp)
if s == t:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import sys
from collections import Counter


def main():
    s = input()
    t = input()
    s_count = [0]*26
    t_count = [0]*26
    for i in range(ord("a"), ord("z")+1):
        s_count[i-97] = s.count(chr(i))
        t_count[i-97] = t.count(chr(i))
    s_count.sort()
    t_count.sort()
    if s_count == t_count:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    S = input().rstrip()
    T = input().rstrip()
    L = [[S[i],T[i]] for i in range(len(S))]
    L.sort(key = lambda x: x[0])
    D = defaultdict(int)
    D2 = defaultdict(int)
    for a, b in L:
        if (D[a] == 0 or D[a] == b) and (D2[b] == 0 or D2[b] == a):
            D[a]=b
            D2[b]=a
        else:
            print("No")
            exit()
    print("Yes")
    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
T = input()
s_let = [0]*26
t_let = [0]*26
ans = "Yes"

for i in range(len(S)):
  s_let[ord(S[i])-ord("a")] += 1
for j in range(len(T)):
  t_let[ord(T[j])-ord("a")] += 1

s_let.sort()
t_let.sort()

for k in range(26):
  if s_let[k] != t_let[k]:
    ans = "No"

print(ans)

Submission status: Accepted

Solution code:
import collections

A = input()
B = input()

A_c = collections.Counter(A)
B_c = collections.Counter(B)
A_c = A_c.values()
B_c = B_c.values()

A_c = list(A_c)
B_c = list(B_c)
A_c.sort()
B_c.sort()
if A_c == B_c:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
s = input()
t = input()
x = []
y = []
for i in range(len(s)):
    if s[i] not in x:
        x.append(s[i])
    if t[i] not in y:
        y.append(t[i])
for i in range(len(x)):
    s = s.replace(x[i], str(i))
for i in range(len(y)):
    t = t.replace(y[i], str(i))
if s == t:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter

def main():
    S = input()
    T = input()
    cnt_S = []
    cnt_T = []
    for i, j in Counter(S).items():
        cnt_S.append(j)
    for i, j in Counter(T).items():
        cnt_T.append(j)

    cnt_S.sort()
    cnt_T.sort()
    if cnt_T == cnt_S:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(S, T):
    N = len(S)
    S_check = [0] * N
    T_check = [0] * N
    for i in range(N):
        if S_check[i] == 0:
            S_check[i] = 1
            for j in range(i + 1, N):
                if S[i] == S[j]:
                    S_check[j] = 1
                    if T[i] != T[j]:
                        print('No')
                        return
        if T_check[i] == 0:
            T_check[i] = 1
            for j in range(i + 1, N):
                if T[i] == T[j]:
                    T_check[j] = 1
                    if S[i] != S[j]:
                        print('No')
                        return
    print('Yes')


if __name__ == '__main__':
    S = input()
    T = input()
    solve(S, T)

    # # test
    # from random import randint
    # from func import random_str
    # S = 'abcdefghijklmnopqrstuvwxyz' * (2 * 10 ** 5 // 26 + 1)
    # T = 'abcdefghijklmnopqrstuvwxyz' * (2 * 10 ** 5 // 26 + 1)
    # solve(S, T)

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(S, T):
    alp = 'abcdefghijklmnopqrstuvwxyz'
    N = len(S)
    S_same = [[] for _ in range(N)]
    S_alphabet = {s: [] for s in alp}
    T_same = [[] for _ in range(N)]
    T_alphabet = {s: [] for s in alp}
    for i in range(N):
        S_alphabet[S[i]].append(i)
        T_alphabet[T[i]].append(i)
    for s in alp:
        stmp = S_alphabet[s]
        ttmp = T_alphabet[s]
        if len(stmp) > 0:
            S_same[stmp[0]] = stmp.copy()
        if len(ttmp) > 0:
            T_same[ttmp[0]] = ttmp.copy()
    for i in range(N):
        if len(S_same[i]) > 1:
            for ss in S_same[i][1:]:
                if T[S_same[i][0]] != T[ss]:
                    print('No')
                    return
        if len(T_same[i]) > 1:
            for tt in T_same[i][1:]:
                if S[T_same[i][0]] != S[tt]:
                    print('No')
                    return
    print('Yes')


if __name__ == '__main__':
    S = input()
    T = input()
    solve(S, T)

    # # test
    # from random import randint
    # from func import random_str
    # solve()

Submission status: Accepted

Solution code:
s=list(input())
t=list(input())

n=len(s)
ch=0
ch1=0
ans=0

d={}
d1={}

st=1
st1=1

s_new=[]
t_new=[]

for i in range(n):
  if s[i] not in d:
    d[s[i]]=st
    st+=1
    
for g in range(n):
  if t[g] not in d1:
    d1[t[g]]=st1
    st1+=1
    
for h in range(n):
  s_new.append(d[s[h]])
  t_new.append(d1[t[h]])
  
if s_new==t_new:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


alphabet = [chr(i+97) for i in range(26)]
dS,dT = {},{}
for s in alphabet:
    dS[s] = []
    dT[s] = []

S,T = LS2(),LS2()
N = len(S)
for i in range(N):
    dS[S[i]].append(i)
    dT[T[i]].append(i)

count_S,count_T = [0]*N,[0]*N  # Si,Ti と同じ文字が何回現れるか
for i in range(N):
    count_S[i] = len(dS[S[i]])
    count_T[i] = len(dT[T[i]])

print('Yes' if count_S == count_T else 'No')

Submission status: Accepted

Solution code:
S=input()
T=input()
N=len(S)
d=dict()
for i in range(N):
    if S[i] not in d.keys():
        if T[i] in d.values():
            print("No")
            break
        d[S[i]]=T[i]
    else:
        if d[S[i]]!=T[i]:
            print("No")
            break
else:
    print("Yes")

Submission status: Accepted

Solution code:
S = input()
T = input()
sdic = {}
tdic = {}
flag = True
for s, t in zip(S, T):
  if s not in sdic:
    sdic[s] = t
  if t not in tdic:
    tdic[t] = s
  if sdic[s] != t or tdic[t] != s:
    flag = False
    break
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():


    s = S()
    t = S()
    
    dic1 = collections.defaultdict(str)
    dic2 = collections.defaultdict(str)
    
    for i in range(len(s)):
        if dic1[t[i]] == "":
            dic1[t[i]] = s[i]
        else:
            if dic1[t[i]] != s[i]:
                print("No")
                exit(0)

        if dic2[s[i]] == "":
            dic2[s[i]] = t[i]
        else:
            if dic2[s[i]] != t[i]:
                print("No")
                exit(0)
        
    print("Yes")

main()

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    S = SI()
    T = SI()
    
    
    ord_S = [0 for _ in range(26)]
    ord_T = [0 for _ in range(26)]
    
    for n in range(len(S)):
        ord_S[ord(S[n])-97] += 1
        ord_T[ord(T[n])-97] += 1
    
    
    s_ord_S = sorted(ord_S)
    s_ord_T = sorted(ord_T)
    
    for p in range(26):
        if s_ord_S[p] != s_ord_T[p]:
            print("No")
            sys.exit()
    print("Yes")
        

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input():
  return sys.stdin.readline().rstrip()

S=input()
T=input()

ok=True
a,b={},{}
for i in range(len(S)):
  s=S[i]
  t=T[i]
  if s in a:
    if a[s]!=t:
      ok=False
  if t in b:
    if b[t]!=s:
      ok=False
  a[s]=t
  b[t]=s

print("Yes" if ok else "No")

Submission status: Accepted

Solution code:
S=input()
T=input()

ok=True
a,b={},{}
for i in range(len(S)):
  s=S[i]
  t=T[i]
  if s in a:
    if a[s]!=t:
      ok=False
  if t in b:
    if b[t]!=s:
      ok=False
  a[s]=t
  b[t]=s

print("Yes" if ok else "No")

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

S = input()
S = S.replace('\n','')
s_list = list(S)

T = input()
T = T.replace('\n','')
t_list = list(T)

alpha_dict = {}
t_diff_count = [0 for i in range(27)]
s_diff_count = [0 for i in range(27)]

for i,c in enumerate(range(ord('a'),ord('z')+1)):
    alpha_dict[chr(c)] = i 

for i,s in enumerate(s_list):
    #if not s == t_list[i]:
    number = alpha_dict[s_list[i]]
    s_diff_count[number] += 1
    number = alpha_dict[t_list[i]]
    t_diff_count[number] += 1

for i,s in enumerate(s_list):
    number = alpha_dict[s_list[i]]
    s_count = s_diff_count[number] 
    number = alpha_dict[t_list[i]]
    t_count = t_diff_count[number]
    if not s_count == t_count:
        if t_count >= 2:
            print("No")
            exit(0)
        if s_count >= 2:
            print("No")
            exit(0)
print("Yes")

Submission status: Accepted

Solution code:
import collections
a = list(input())
b = list(input())
A = collections.Counter(a)
B = collections.Counter(b)
Alist = list(A.values())
Blist = list(B.values())
Asort = sorted(Alist)
Bsort = sorted(Blist)
if Asort == Bsort:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
S = input()
T = input()
U = [[i,j] for i,j in zip(S,T)]
U.sort()
s = U[0][0]
t = U[0][1]
for i,j in U:
    if  i != s:
        s = i
        t = j
    elif j != t:
        print("No")
        exit()
U.sort(key=lambda x:x[1])
s = U[0][0]
t = U[0][1]
for i,j in U:
    if j != t:
        s = i
        t = j
    elif i != s:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    S = input().strip()
    T = input().strip()
    s_t = {}
    t_s = {}
    for s, t in zip(S, T):
        if s not in s_t and t not in t_s:
            s_t[s] = t
            t_s[t] = s
        elif s in s_t and t in t_s:
            if not (s_t[s] == t and t_s[t] == s):
                return 'No'
        else:
            return 'No'
    return 'Yes'



if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
S = input()
T = input()
length = len(S)
keep_S = [[] for i in range(26)]  # ord(T[i])に対応する S を格納
keep_T = [[] for i in range(26)]  # ord(S[i])に対応する T を格納

for i in range(length):

    num_S = ord(T[i]) - ord('a')
    num_T = ord(S[i]) - ord('a')

    if S[i] in keep_S[num_S]:
        continue
    else:
        keep_S[num_S].append(S[i])

    if T[i] in keep_T[num_T]:
        continue
    else:
        keep_T[num_T].append(T[i])


for i in range(26):
    if (len(keep_T[i]) > 1) | (len(keep_S[i]) > 1):
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
S = input()
T = input()

chk1 = [[] for _ in range(26)]
chk2 = [[] for _ in range(26)]
for i in range(len(S)):
    s1 = ord(S[i]) - 97
    s2 = ord(T[i]) - 97
    if len(chk1[s1]) == 0:
        chk1[s1].append(T[i])
    else:
        if chk1[s1][0] == T[i]:
            pass
        else:
            print('No')
            exit()
    if len(chk2[s2]) == 0:
        chk2[s2].append(S[i])
    else:
        if chk2[s2][0] == S[i]:
            pass
        else:
            print('No')
            exit()    
print('Yes')

Submission status: Accepted

Solution code:
S = input()
T = input()
N = len(S)
SD = {}
TD = {}
SN = [0]*N
TN = [0]*N
count = 1
for i in range(N):
  s = S[i]
  if s not in SD:
    SD[s] = count
    count+=1
  SN[i] = SD[s]
count = 1
for i in range(N):
  t = T[i]
  if t not in TD:
    TD[t] = count
    count+=1
  TN[i] = TD[t]
ans = "Yes"
for i in range(N):
  if SN[i]!=TN[i]:
    ans = "No"
    break
print(ans)

Submission status: Accepted

Solution code:
# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

S = input()
T = input()

sd = defaultdict(lambda: ".")
td = defaultdict(lambda: ".")

for s, t in zip(S, T):
    if sd[s] != "." and sd[s] != t:
        print("No")
        exit()
    if td[t] != "." and td[t] != s:
        print("No")
        exit()
    sd[s] = t
    td[t] = s
print("Yes")

Submission status: Accepted

Solution code:
S=input()
T=input()
alp=[chr(i) for i in range(97, 97+26)]
words_T=[[] for _ in range(len(alp))]
words_S=[[] for _ in range(len(alp))]
num=0
for al in alp:
    for n in range(len(T)):
        if T[n]==al:
            words_T[num].append(n)
    num+=1
num=0
for al in alp:
    for n in range(len(T)):
        if S[n]==al:
            words_S[num].append(n)
    num+=1
flag=0
for word in words_T:
    if len(word)<=1:
        continue
    wo=S[word[0]]
    for w in word:
        if wo==S[w]:
            continue
        else:
            flag=1
            break
for word in words_S:
    if len(word)<=1:
        continue
    wo=T[word[0]]
    for w in word:
        if wo==T[w]:
            continue
        else:
            flag=1
            break
if flag==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s = input()
t = input()

l_s = [[] for _ in range(26)]

for i, x in enumerate(s):
    l_s[ord(x) - 97].append(i)

l_t = [[] for _ in range(26)]
for i, x in enumerate(t):
    l_t[ord(x) - 97].append(i)

for l in l_s:
    if len(l) > 0:
        if l_t[ord(t[l[0]]) - 97] != l:
            print('No')
            exit()

print('Yes')

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    s = input()
    t = input()
    import string

    l = string.ascii_lowercase

    for i in l:
        trial = set()
        for k,j in enumerate(s):
            if i == j:
                trial.add(t[k])
                if len(trial) > 1:
                    print("No")
                    exit()
        trial = set()
        for k,j in enumerate(t):
            if i == j:
                trial.add(s[k])
                if len(trial) > 1:
                    print("No")
                    exit()

    print("Yes")



if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
s=input()
t=input()

t1=0
l1={}
sl=[]
for i in s:
  if i in l1:
    sl.append(l1[i])
  else:
    l1[i]=t1
    sl.append(t1)
    t1+=1

t2=0
l2={}
tl=[]
for i in t:
  if i in l2:
    tl.append(l2[i])
  else:
    l2[i]=t2
    tl.append(t2)
    t2+=1
print("Yes" if sl==tl else "No")

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

S,T=input(),input()
C=[-1]*26
D=set(list(range(26)))
ans=True
for i in range(len(S)):
    s,t=ston(S[i]),ston(T[i])
    if C[s]!=t:
        if C[s]!=-1 or t not in D:
            ans=False
            break
        D.remove(t)
        C[s]=t
judge(ans)

Submission status: Accepted

Solution code:
def main():
    dic1 = {}
    dic2 = {}
    S = list(input().rstrip())
    T = list(input().rstrip())
    for s, t in zip(S, T):
        if s not in dic1:
            dic1[s] = t
        elif dic1[s] != t:
            print('No')
            exit()
        if t not in dic2:
            dic2[t] = s
        elif dic2[t] != s:
            print('No')
            exit()
    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
# sys.setrecursionlimit(100000)
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    T = input()
    S_cnt = Counter(S).most_common()
    T_cnt = Counter(T).most_common()
    if len(S_cnt) != len(T_cnt):
        print("No")
        return
    for i in range(len(S_cnt)):
        if S_cnt[i][1] == T_cnt[i][1]:
            continue
        else:
            print("No")
            return
    print("Yes")
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
n = len(s)

s_par = [i for i in range(n + 1)]
t_par = [i for i in range(n + 1)]

def operation(x, par):
    for i in range(n):
        for j in range(i):
            if x[i] == x[j]:
                par[i] = par[j]
                break
    return par

if operation(s, s_par) == operation(t, t_par):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
n = len(s)

s_par = [i for i in range(n + 1)]
t_par = [i for i in range(n + 1)]

for i in range(n):
    for j in range(i):
        if s[i] == s[j]:
            s_par[i] = s_par[j]
            break
            
for i in range(n):
    for j in range(i):
        if t[i] == t[j]:
            t_par[i] = t_par[j]
            break
            
if s_par == t_par:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s = input()
t = input()
n = len(s)
x = []
y = []

for i in range(n):
    if s[i] not in x:
        x.append(s[i])
    if t[i] not in y:
        y.append(t[i])

for i in range(len(x)):
    s = s.replace(x[i], str(i))
for i in range(len(y)):
    t = t.replace(y[i], str(i))
print('Yes' if s == t else 'No')

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())

s = list(map(ord, s))
t = list(map(ord, t))
s_to_t = [-1] * 200
t_to_s = [-1] * 200

for i in range(len(s)):
    if s_to_t[s[i]] == -1:
        s_to_t[s[i]] = t[i]
    else:
        if s_to_t[s[i]] != t[i]:
            print("No")
            break
    if t_to_s[t[i]] == -1:
        t_to_s[t[i]] = s[i]
    else:
        if t_to_s[t[i]] != s[i]:
            print("No")
            break
else:
    print("Yes")

Submission status: Accepted

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop, heapify
import copy
import numpy as np
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


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

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    s = S()
    t = S()
    s_c = Counter(s)
    s_t = Counter(t)
    if sorted(s_c.values()) == sorted(s_t.values()):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import collections
S = list(input())
T = list(input())
counterS = collections.Counter(S)
counterT = collections.Counter(T)
Scou = list(counterS.values())
Tcou = list(counterT.values())
Scou.sort()
Tcou.sort()
if Scou == Tcou:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s=list(input())
t=list(input())
n=len(s)
def get_count_list(s):
    alphabets="abcdefghijklmnopqrstuvwxyz"
    ans={}
    for alphabet in alphabets:
        ans[alphabet]=[]
    for i in range(n):
        ans[s[i]].append(i)
    return ans


def get_index2alpha(s):
    ans={}
    for i in range(n):
        ans[i]=s[i]
    return ans

s_count=get_count_list(s)
t_count=get_count_list(t)
s_index=get_index2alpha(s)
t_index=get_index2alpha(t)

ans=0

s_set=set(s)


for i in range(n):
    s_alpha=s_index[i]
    t_alpha = t_index[i]
    if s_alpha in s_set:
        s_set.remove(s_alpha)
        if not s_count[s_alpha]==t_count[t_alpha]:
            ans+=1

if ans==0:
    print("Yes")
else:
    print("No")