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: Accepted

Solution code:
import collections
S = input()
T = input()
scounter = collections.Counter(S)
tcounter = collections.Counter(T)
scounter_v = dict(scounter).values()
tcounter_v = dict(tcounter).values()
sdist = sorted([i for i in scounter_v])
tdist = sorted([i for i in tcounter_v])
if sdist == tdist:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
def f():
  i = input()
  return sorted(i.count(j) for j in set(i))
print("YNeos"[f()!=f()::2])

Submission status: Accepted

Solution code:
from collections import*
c = Counter
f = lambda: c(c(input()).values())
print("YNeos"[f()!=f()::2])

Submission status: Accepted

Solution code:
from collections import defaultdict
s = input()
t = input()
sd = defaultdict(set)
td = defaultdict(set)
for i in range(len(s)):
    sd[s[i]].add(t[i])
    td[t[i]].add(s[i])
if [1 for i in sd.values() if len(i)!=1] or [1 for i in td.values() if len(i)!=1]:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

a = [[] for i in range(26)]
for i in range(len(s)):
    a[ord(s[i])-97].append(i)

b = [[] for i in range(26)]
for i in range(len(t)):
    b[ord(t[i])-97].append(i)

a.sort()
b.sort()

for i in range(26):
    if (a[i]!=b[i]):
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys

S=input()
T=input()
n=len(S)
D={}
C=[]
for i in range(n):
    if not S[i] in D:
        if T[i] in C:
            print("No")
            sys.exit()
        D[S[i]]=T[i]
        C.append(T[i])
    else:
        if D[S[i]]!=T[i]:
            print("No")
            sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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


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

    cnt_S = {}
    for s in S:
        if s not in cnt_S:
            cnt_S[s] = 1
        else:
            cnt_S[s] += 1

    cnt_T = {}
    for t in T:
        if t not in cnt_T:
            cnt_T[t] = 1
        else:
            cnt_T[t] += 1

    if len(cnt_S) != len(cnt_T):
        print("No")
    else:
        cnt_S = [v for v in cnt_S.values()]
        cnt_T = [v for v in cnt_T.values()]
        cnt_S.sort()
        cnt_T.sort()
        ans = True
        for s, t in zip(cnt_S, cnt_T):
            if s != t:
                ans = False
                break
        if ans:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    S = input()
    T = input()
    dic_s = {}
    dic_t = {}
    for i in range(len(S)):
        s = S[i]
        t = T[i]
        if s in dic_t:
            if dic_t[s] != t:
                print('No')
                exit()
        if t in dic_s:
            if dic_s[t] != s:
                print('No')
                exit()
        dic_t[s] = t
        dic_s[t] = s
    print('Yes')
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
s = input()
t = input()
scnt = {}
tcnt = {}
sres = []
tres = []
for x in s:
    if x not in scnt:scnt[x] = 1
    else:scnt[x] +=1
for x in t:
    if x not in tcnt:tcnt[x] = 1
    else:tcnt[x] +=1
for k in scnt:
    sres.append(scnt[k])
for k in tcnt:
    tres.append(tcnt[k])
sres.sort()
tres.sort()
n = max(len(sres),len(tres))
ok = True
for i in range(n):
    if sres[i] != tres[i]:
        ok = False
        break
if ok:print('Yes')
else:print('No')

Submission status: Accepted

Solution code:
str1 = input()
str2 = input()

dict1 = dict()
ans = "Yes"

for i in range(len(str1)):
    if(str1[i] in dict1.keys()):
        if(dict1[str1[i]] != str2[i]):
            ans = "No"
    else:
        if(str2[i] in dict1.values()):
            ans = "No"
        dict1[str1[i]] = str2[i]

print(ans)

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
ls, lt = len(s), len(t)
ss = [0] * ls
alph1 = [-1] * 130
alph2 = [-1] * 130
for i in range(ls):
    c = 1
    m, n = ord(s[i]), ord(t[i])
    if alph1[m] == -1:
        alph1[m] = ord(t[i])
    else:
        if not alph1[m] == ord(t[i]):
            c = 0
    if alph2[n] == -1:
        alph2[n] = ord(s[i])
    else:
        if not alph2[n] == ord(s[i]):
            c = 0
    if c == 0:
        break
print("Yes" if c == 1 else "No")

Submission status: Accepted

Solution code:
from collections import Counter
 
def check():
    S = sorted(Counter(input()).values())
    T = sorted(Counter(input()).values())
    
    for s,t in zip(S,T):
        if s !=t: # 置換できるならば要素の数は同じになるはず
            return 'No'
    return 'Yes'
  
print(check())

Submission status: Accepted

Solution code:
import sys, copy, math, heapq, bisect
from itertools import accumulate
from collections import deque, defaultdict, Counter
input = sys.stdin.readline # 文字列の入力のとき'/n'まで受け取るので注意!!!
sys.setrecursionlimit(500000)

S = input()
T = input()
N = len(S)
ds = {}
dt = {}
ss = 0
tt = 0
SS = []
TT = []
for i in range(N):
    if S[i] in ds:
        SS.append(ds[S[i]])
    else:
        ds[S[i]] = ss
        SS.append(ss)
        ss += 1
    if T[i] in dt:
        TT.append(dt[T[i]])
    else:
        dt[T[i]] = tt
        TT.append(tt)
        tt += 1
flag = True
for i in range(N):
    if SS[i]==TT[i]:
        continue
    else:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def isOK(s,t):
  m = [None] * 26
  for i,j in zip(s,t):
    num = ord(i) - ord("a")
    if m[num] == None:
      m[num] = j
    else:
      if m[num] != j:
        return False
  return True

s = input()
t = input()
if isOK(s,t) and isOK(t,s):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
s = input()
t = input()
replace_s = {chr(i): '' for i in range(ord('a'), ord('z')+1)}
replace_t = {chr(i): '' for i in range(ord('a'), ord('z')+1)}
ans = 'Yes'
for i, j in zip(s, t):
    if replace_s[i] and replace_s[i] != j or replace_t[j] and replace_t[j] != i:
        ans = 'No'
        break
    if not replace_s[i]:
        replace_s[i] = j
    if not replace_t[i]:
        replace_t[j] = i
print(ans)

Submission status: Accepted

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

    spair = {}
    tpair = {}

    for s, t in zip(S, T):
        if s not in spair:
            spair[s] = t
        else:
            if spair[s] != t:
                print("No")
                exit()
        if t not in tpair:
            tpair[t] = s
        else:
            if tpair[t] != s:
                print("No")
                exit()

    print("Yes")


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)


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


S, T = input(), input()

m = {}
ok = True
for s, t in zip(S, T):
    if s in m and m[s] != t:
        ok = False
        break
    m[s] = t
print('Yes' if ok and len(m.values()) == len(set(m.values())) else 'No')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)

def main():
    S = input()
    T = input()
    pair1 = {}
    pair2 = {}
    for i in range(len(S)):
        if S[i] not in pair1.keys():
            pair1[S[i]] = T[i]
        else:
            if pair1[S[i]] != T[i]:
                print('No')
                return
        if T[i] not in pair2.keys():
            pair2[T[i]] = S[i]
        else:
            if pair2[T[i]] != S[i]:
                print('No')
                return
        
    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)

def main():
    S = input()
    T = input()
    pair = {}
    pair2 = {}
    for i in range(len(S)):
        if S[i] not in pair.keys():
            pair[S[i]] = T[i]
        else:
            if pair[S[i]] != T[i]:
                print('No')
                return
        if T[i] not in pair2.keys():
            pair2[T[i]] = S[i]
        else:
            if pair2[T[i]] != S[i]:
                print('No')
                return
        
    
    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ch = list("abcdefghijklmnopqrstuvwxyz")

s = list(input())
t = list(input())
import numpy as np

s = np.array(s)
t = np.array(t)

flag = True
for i in ch:
  t_temp = (t[s == i])
  s_temp = (s[t == i])
  if len(set(t_temp)) > 1 or len(set(s_temp)) > 1:
    flag = False
    
if flag:print("Yes")
else:print("No")

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

s = sorted(Counter(list(readline().rstrip().decode())).values())
t = sorted(Counter(list(readline().rstrip().decode())).values())
if s == t:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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


def check(S,T):
    dic1 = {}
    dic2 = {}
    for s,t in zip(S,T):
        if s not in dic1:
            dic1[s] = t
            # dic2[s] = False
        elif dic1[s] != t:
            return False
    for k in dic1.keys():
        if list(dic1.values()).count(k) > 1:
            return False
        # if dic2[k]==False:
        #     mark = False
        #     first = k #最初の文字を記録する
        #     while True:
        #         dic2[k] = True
        #         k = dic1[k]
        #         if k not in dic1 or k == first: #辞書にない文字or最初の文字
        #             mark = True #OK
        #             break
        #         elif dic2[k] == True:
        #             break
        #     if mark == False:
        #         return False
    return True
            

if check(S,T):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

dic = {}
dic2 = {}
for i in range(len(s)):
  tmp = dic.get(s[i],-1)
  tmp2 = dic2.get(t[i],-1)
  if tmp != -1 and tmp != t[i]:
    print('No')
    sys.exit(0)
    
  if tmp2 != -1 and tmp2 != s[i]:
    print('No')
    sys.exit(0)
    
  if tmp == -1:
    dic[s[i]] = t[i]
    
  if tmp2 == -1:
    dic2[t[i]] = s[i]

print('Yes')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#110_c

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

    start = [-1]*26
    goal  = [-1]*26

    for i in range(len(S)):
        a = ord(S[i]) - ord('a')
        b = ord(T[i]) - ord('a')

        if (start[a] != -1 or goal[b] != -1) and (start[a] != b or goal[b] != a):
            print("No")
            return
        else:
            start[a] = b
            goal[b]  = a
    print("Yes")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#110_c

S = input()
T = input()

combination = []
for i, j in zip(S,T):
    combination.append([i,j])

set_S = []
set_T = []

for i,j in list(map(list, set(map(tuple, combination)))):
    set_S.append(i)
    set_T.append(j)

if len(set_S) == len(set(set_S))and len(set_T) == len(set(set_T)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter

def check():
    S = sorted(Counter(input()).values())
    T = sorted(Counter(input()).values())
    
    for s,t in zip(S,T):
        if s !=t:
            return 'No'
    return 'Yes'
  
print(check())

Submission status: Accepted

Solution code:
# Problem C - String Transformation

# input
S = list(input())
T = list(input())

# initialization
s_map = {}
t_map = {}
is_ok = True

# mapping
for i in range(len(S)):
    s = S[i]
    t = T[i]
    if not s in s_map:
        s_map[s] = set([t])
    else:
        s_map[s].add(t)

    if not t in t_map:
        t_map[t] = set([s])
    else:
        t_map[t].add(s)

# check
# s check
for s in s_map:
    if len(s_map[s])>1:
        is_ok = False
# t check
for t in t_map:
    if len(t_map[t])>1:
        is_ok = False

# output
if is_ok:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
from string import ascii_lowercase

o = dict(zip(ascii_lowercase, range(26)))

s, t = sys.stdin.read().split()

def main():
    g1 = [set() for _ in range(26)]
    g2 = [set() for _ in range(26)]
    for i in range(len(s)):
        a = o[s[i]]; b = o[t[i]]
        g1[a].add(b); g2[b].add(a)

    for i in range(26):
        if len(g1[i]) >= 2 or len(g2[i]) >= 2:
            print('No')
            return
    print('Yes')

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def o(c): return ord(c) - ord('a')

s, t = sys.stdin.read().split()

def main():
    g1 = [set() for _ in range(26)]
    g2 = [set() for _ in range(26)]
    for i in range(len(s)):
        a = o(s[i]); b = o(t[i])
        g1[a].add(b); g2[b].add(a)

    for i in range(26):
        if len(g1[i]) >= 2 or len(g2[i]) >= 2:
            print('No')
            return
    print('Yes')

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    # S: azzel
    # T: apple
    S = input()
    T = input()
    ok = True
    dic_s = {}
    dic_t = {}
    for i in range(len(S)):
        s = S[i]
        t = T[i]
        if s in dic_s.keys():
            if dic_s[s] != t:
                ok = False
        if t in dic_t.keys():
            if dic_t[t] != s:
                ok = False
        dic_s[s] = t
        dic_t[t] = s
        #print(dic_s,dic_t,sep='\n')
    if ok:
        print('Yes')
    else:
        print('No')



if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:


def solve():

    s = input()
    t = input()

    dict_st = {}
    dict_ts = {}

    for x, y in zip(s, t):
        if x not in dict_st:
            dict_st[x] = y
        else:
            if dict_st[x] != y:
                print("No")
                break

        if y not in dict_ts:
            dict_ts[y] = x
        else:
            if dict_ts[y] != x:
                print("No")
                break
    else:
        print("Yes")


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from collections import defaultdict
d1 = defaultdict(list)
d2 = defaultdict(list)
S = input()
T = input()
N = len(S)
for i in range(N):
    d1[S[i]].append(i)
for i in range(N):
    d2[T[i]].append(i)
val1 = d1.values()
val2 = d2.values()
val1 = list(val1)
val2 = list(val2)
val1.sort()
val2.sort()
if val1 == val2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import string
import collections
S = input()
T = input()
s_cnt =collections.Counter(list(S))
n_cnt = collections.Counter(list(T))
#print(s_cnt, n_cnt)

for i in range(len(s_cnt)):
  if(s_cnt.most_common()[i][1] != n_cnt.most_common()[i][1]):
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
s = str(input())
t = str(input())
ls = [[0] for i in range(26)]
lt = [[0] for i in range(26)]
for i in range(len(s)):
    ls[ord(s[i])-97].append(i)
    lt[ord(t[i])-97].append(i)
for i in ls:
    for j in lt:
        if i==j:
            break
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
s=list(input())
t=list(input())
c=[chr(i) for i in range(97, 97+26)]
l=[[] for i in range(26)]
l2=[[] for i in range(26)]
for i in range(len(s)):
  l[c.index(s[i])].append(t[i])
  l2[c.index(t[i])].append(s[i])
for i in range(26):
  if len(set(l[i]))>1 or len(set(l2[i]))>1:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
"""
嘘解法です.通るかな?
コーナーケース:
in:
    abab
    aabb
Out:
    Yes
    (本当はNo)
"""
s = str(input())
t = str(input())
ls = [0]*26
lt = [0]*26
for i in range(len(s)):
    ls[ord(s[i])-97] += 1
    lt[ord(t[i])-97] += 1
ls.sort()
lt.sort()
if lt == ls:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
s=input()
t=input()
dict_s = {}
dict_t = {}
ans = 0

for i in range(len(s)):
    s1 = s[i]
    if s1 in dict_s.keys():
        dict_s[s1] += 1
    else:
        dict_s[s1] = 1

for i in range(len(t)):
    t1 = t[i]
    if t1 in dict_t.keys():
        dict_t[t1] += 1
    else:
        dict_t[t1] = 1

for i in range(len(s)):
    if dict_s[s[i]] != dict_t[t[i]]:
        ans = 1
        break

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

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
tr = []
a_ar =[chr(ord('a') + i) for i in range(26)]
a_edge = []
for i in range(26):
    a_edge.append(set())
for i in range(len(s)):
    a_edge[a_ar.index(s[i])].add(a_ar.index(t[i]))

ans = []
for i in range(26):
    if len(a_edge[i]) >= 2:
        print("No")
        exit()
    elif len(a_edge[i]) != 0:
        l = list(a_edge[i])
        ans.append(l[0])
p = len(ans)
q = len(set(ans))
if p == q:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
s = str(input())
t = str(input())
ls = [[0] for i in range(26)]
lt = [[0] for i in range(26)]

for i in range(len(s)):
    ls[ord(s[i])-97].append(i)
    lt[ord(t[i])-97].append(i)
# print(ls)
# print(lt)
for i in ls:
    f = 0
    for j in lt:
        if i==j:
            f = 1
            break
    if f == 0:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
def c_string_transformation():
    from collections import defaultdict
    S,T = input(),input()
    dict_s_to_t = defaultdict(set)
    dict_t_to_s = defaultdict(set)
    for c1, c2 in zip(S, T):
        dict_s_to_t[c1].add(c2)
        dict_t_to_s[c2].add(c1)
    # ディクショナリの各要素について，値の長さが 2 以上だと，
    # ある英小文字と 2 つ以上の英小文字との間に対応がある (全単射でない)
    # そうなると，S を T に一致させることはできない
    # 全単射であることを調べるため，両方のディクショナリを検査する
    for v in list(dict_s_to_t.values()) + list(dict_t_to_s.values()):
        if len(v) != 1:
            return 'No'
    return 'Yes'

print(c_string_transformation())

Submission status: Accepted

Solution code:
import sys
s=list(input())
t=list(input())
c=[chr(i) for i in range(97, 97+26)]
l=[[] for i in range(26)]
l2=[[] for i in range(26)]
for i in range(len(s)):
  l[c.index(s[i])].append(t[i])
  l2[c.index(t[i])].append(s[i])
for i in range(26):
  l[i]=list(set(l[i]))
  l2[i]=list(set(l2[i]))
for i in range(26):
  if len(l[i])>=2:
    print('No')
    sys.exit()
  if len(l2[i])>=2:
    print('No')
    sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
# きりみんちゃんの配信からきました
# 登場回数が同一ならいけそうなのでそうする
s, t = input(), input()
sd, td = {}, {}
for sv in s:
    if sv in sd:
        sd[sv] += 1
    else:
        sd[sv] = 1
for tv in t:
    if tv in td:
        td[tv] += 1
    else:
        td[tv] = 1
sort_sk, sort_tk = sorted(sd.values()), sorted(td.values())
print("Yes" if sort_sk == sort_tk else "No")

Submission status: Accepted

Solution code:
S = input()
T = input()
dis = {}
dit = {}
for s, t in zip(S,T):
    if s in dis:
        if dis[s]!=t:
            print('No')
            break
    else:
        dis[s] = t
    if t in dit:
        if dit[t]!=s:
            print('No')
            break
    else:
        dit[t] = s
else:
    print('Yes')

Submission status: Accepted

Solution code:
s=input()
t=input()
sr=[-1]*26
tr=[-1]*26
ans="Yes"
for S,T in zip(s,t):
    if sr[ord(S)-97]>=0:
        if sr[ord(S)-97]!=ord(T):
            ans="No"
    if tr[ord(T)-97]>=0:
        if tr[ord(T)-97]!=ord(S):
            ans="No"
    if sr[ord(S)-97]<0:
        sr[ord(S)-97]=ord(T)
    if tr[ord(T)-97]<0:
        tr[ord(T)-97]=ord(S)
print(ans)

Submission status: Accepted

Solution code:
# きりみんちゃんの配信からきました
# 登場回数が同一ならいけそうなのでそうする
from string import ascii_lowercase
s, t = input(), input()
alphabets = ascii_lowercase
sd, td = {}, {}
for sv in s:
    if sv in sd:
        sd[sv] += 1
    else:
        sd[sv] = 1
for tv in t:
    if tv in td:
        td[tv] += 1
    else:
        td[tv] = 1
sort_sk = sorted(sd.values())
sort_tk = sorted(td.values())
print("Yes" if sort_sk == sort_tk else "No")

Submission status: Accepted

Solution code:
from collections import defaultdict

s = input()
t = input()

def fprint(x):
    d = defaultdict(list)
    for i, c in enumerate(x):
        d[c].append(i)
    return sorted(d.values())

sf = fprint(s)
tf = fprint(t)
if sf == tf:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
S, T = input().strip(), input().strip()
ds, dt = {}, {}

for s, t in zip(S, T):
    if s not in ds or ds[s] == t:
        ds[s] = t
    else:
        print('No')
        exit()
    if t not in dt or dt[t] == s:
        dt[t] = s
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
from collections import defaultdict
S, T = map(lambda x: x.strip(), open(0).read().split())

ds, dt = defaultdict(str), defaultdict(str)
ans = 'Yes'
for s, t in zip(S, T):
    if not ds[s] or ds[s] == t:
        ds[s] = t
    else:
        ans = 'No'
        break
    if not dt[t] or dt[t] == s:
        dt[t] = s
    else:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

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

ds = {}
dt = {}
ans = 'Yes'
for s, t in zip(S, T):
    if s not in ds or ds[s] == t:
        ds[s] = t
    else:
        ans = 'No'
        break
    if t not in dt or dt[t] == s:
        dt[t] = s
    else:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
a = input()
b = input()
relsa = {}
relsb = {}
possible = True
for i in range(len(a)):
  if a[i] not in relsa:
    relsa[a[i]] = b[i]
  else:
    if relsa[a[i]] != b[i]:
      possible = False
  if b[i] not in relsb:
    relsb[b[i]] = a[i]
  else:
    if relsb[b[i]] != a[i]:
      possible = False
      
if possible:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
S=input()
T=input()
Rs=[-1]*26
Rt=[-1]*26
for i in range(len(S)):
  a=ord(S[i])-ord("a")
  b=ord(T[i])-ord("a")
  if Rs[a]==-1:
    Rs[a]=b
  elif Rs[a]!=b:
    print("No")
    exit()
  if Rt[b]==-1:
    Rt[b]=a
  elif Rt[b]!=a:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
s1 = input()
s2 = input()
set1 = set()
li = []
for i in range(len(s1)):
    set1.add((s1[i],s2[i]))
set1 = list(set1)
while set1:
    a = set1.pop()
    #print(set1,a,len(set1))
    for i in range(len(set1)):
        if (a[0] != set1[i][0] and a[1] == set1[i][1]) or (a[0] == set1[i][0] and a[1] != set1[i][1]):
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
s = input()
t = input()
x = len(s)
dic = {}
already = set()
for i in range(x):
    if not s[i] in dic.keys():
        if t[i] in already:
            print("No")
            exit()
        dic[s[i]] = t[i]
        already.add(t[i])
    else:
        if dic[s[i]] != t[i]:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

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

R = [-1] * 26
R2 = [-1] * 26

alpha2num = lambda c: ord(c) - ord('a')

flag = 1

for i in range(len(S)):
  si = alpha2num(S[i])
  ti = alpha2num(T[i])
  
  
  if(R[si] < 0):
    R[si] = ti
    
  if(R2[ti] < 0):
    R2[ti] = si
    
  if(R[si] >= 0):
    if(R[si] != ti):
      flag = 0
      print('No')
      break
      
  if(R2[ti] >= 0):
    if(R2[ti] != si):
      flag = 0
      print('No')
      break
    
if(flag == 1):
  print('Yes')

Submission status: Accepted

Solution code:
s=input()
t=input()
sd={}
td={}
for i in s:
  if i in sd.keys():
    sd[i]+=1
  else:
    sd[i]=1
for i in t:
  if i in td.keys():
    td[i]+=1
  else:
    td[i]=1
if sorted(sd.values()) == sorted(td.values()):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline

S = input().strip()
T = input().strip()

dic_s = Counter([i for i in S])
dic_t = Counter([i for i in T])

arr_s = sorted([i for i in dic_s.values()])
arr_t = sorted([i for i in dic_t.values()])

if arr_s == arr_t:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter
print("Yes" if sorted(Counter(input()).values()) == sorted(Counter(input()).values()) else "No")

Submission status: Accepted

Solution code:
S = input()
T = input()
ListS = []
ListT = []
Alphabet = ["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"]
for i in range(26):
    ListS.append(S.count(Alphabet[i]))
    ListT.append(T.count(Alphabet[i]))
ListS.sort()
ListT.sort()
print("Yes" if ListS == ListT else "No")

Submission status: Accepted

Solution code:
from collections import Counter
s = Counter(input())
a = [i for i in s.values()]
t = Counter(input())
b = [i for i in t.values()]
if sorted(a)==sorted(b):
  print('Yes')
else:
  print("No")

Submission status: Accepted

Solution code:
import collections
s=list(input())
t=list(input())
svalues, scounts = zip(*collections.Counter(s).most_common())
tvalues, tcounts = zip(*collections.Counter(t).most_common())
if scounts==tcounts:print('Yes')
else:print('No')

Submission status: Accepted

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
t = ins()
h = {}
g = {}
for i in range(len(s)):
    if s[i] not in h:
        if t[i] not in g:
            h[s[i]] = t[i]
            g[t[i]] = s[i]
        else:
            print('No')
            exit()
    elif h[s[i]] != t[i]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
s = input()
t = input()
c1 = {}
c2 = {}
for i,j in zip(s,t):
    if i in c1:
      if c1[i] != j:
        a = "No"
        break
    else:
      c1[i] = j
    if j in c2:
      if c2[j] != i:
        a = "No"
        break
    else:
      c2[j] = i
else:
  a = "Yes"
print(a)

Submission status: Accepted

Solution code:
s1 = input()
s2 = input()
N = len(s1)
s1l = []
s2l = []
ans = True
f = False
for i in range(N):
  f = True
  for s in range(len(s1l)):
    if s1[i] == s1l[s]:
      if s2[i] != s2l[s]:
        ans = False
      f = False
      break
    elif s2[i] == s2l[s]:
      ans = False
  if f:
    s1l.append(s1[i])
    s2l.append(s2[i])
if ans:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
from collections import Counter

def can_match(s, t):
  fs = Counter(S)
  ft = Counter(T)
  
  if len(s) != len(t):
    return False
  
  for cs, ct in zip(s, t):
    # 出現頻度が同じであれば変換可能
    if fs[cs] != ft[ct]:
      return False

  return True


S = input()
T = input()

if can_match(S, T):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
def StringTransformation(s , t):

    taious = {}
    taiout = {}
    ans = "Yes"

    for i in range(len(s)):
        if t[i] in taiout.keys() and taiout[t[i]] != s[i]:
            ans = "No"
            break
        elif s[i] in taious.keys() and taious[s[i]] != t[i]:
            ans = "No"
            break
        else:
            taiout[t[i]] = s[i]
            taious[s[i]] = t[i]

    return ans

def main():
    s = str(input())
    t = str(input())
    print(StringTransformation(s , t))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
S = sorted(list(input()))
T = sorted(list(input()))

if Counter(Counter(S).values()) == Counter(Counter(T).values()):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter
s=input()
t=input()
if Counter(Counter(s).values()) == Counter(Counter(t).values()):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
S = input()
T = input()
n = len(S)
s_str = []
s_count = []
t_str = []
t_count = []
for i in range(n):
  if not S[i] in s_str:
    s_str.append(S[i])
    s_count.append(S.count(S[i]))
for i in range(n):
  if not T[i] in t_str:
    t_str.append(T[i])
    t_count.append(T.count(T[i]))
if s_count == t_count:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
s = [c for c in str(input())]
t = [c for c in str(input())]
from collections import Counter
s_cntr = sorted(Counter(s).values())
t_cntr = sorted(Counter(t).values())
if s_cntr == t_cntr: print('Yes')
else: print('No')

Submission status: Accepted

Solution code:
from collections import Counter
import io
import math

sam = sorted(Counter(input()).values())
tim = sorted(Counter(input()).values())

print("Yes" if tim==sam else "No")

Submission status: Accepted

Solution code:
import sys

S = input()
T = input()
alpha_map = {}
talpha_map = {}
for i in range(len(S)):
  s = S[i]
  t = T[i]
  if s in alpha_map.keys():
    if alpha_map[s] != t:
      print("No")
      sys.exit()
  if t in talpha_map.keys():
    if talpha_map[t] != s:
      print("No")
      sys.exit()
  alpha_map[s] = t
  talpha_map[t] = s
print("Yes")