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:
S = input()
T = input()
ans = 'Yes'
dic1,dic2 = {},{}

for i,j in zip(S,T):
    if i in dic1:
        if dic1[i] != j:
            ans = 'No'
    else:
        dic1[i] = j
        
    if j in dic2:
        if dic2[j] != i:
            ans = 'No'
    else:
        dic2[j] = i

#print(dic1)
#print(dic2)
print(ans)

Submission status: Accepted

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

D1={}
D2={}

ans=1
for s,t in zip(S,T):
    x=D1.get(t, '')
    if x=='':
        D1[t]=s
    else:
        if x!=s:
            ans=0
            break
            
    x=D2.get(s, '')
    if x=='':
        D2[s]=t
    else:
        if x!=t:
            ans=0
            break

print('Yes' if ans else 'No')

Submission status: Accepted

Solution code:
from collections import Counter
s = [i for i in str(input())]
t = [h for h in str(input())]
s1 = Counter(s).most_common()
t1 = Counter(t).most_common()
if len(s1) != len(t1):
    print('No')
else:
    z = 'Yes'
    for j in range(len(s1)):
        if s1[j][1] != t1[j][1]:
            z = 'No'
            break
    print(z)

Submission status: Accepted

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

def f(x):
    dic = {}
    for c in x:
        if c in dic:
            dic[c] += 1
        else:
            dic[c] = 1
    return dic

d1 = f(s)
d2 = f(t)
l1 = [i for i in d1.values()]
l2 = [i for i in d2.values()]
l1.sort()
l2.sort()

if l1 == l2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter

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

sc = Counter(s).values()
tc = Counter(t).values()

sl = Counter(sc)
tl = Counter(tc)

if sl == tl:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s = input()
t = input()
cs = []
ct = []
for i in range(97,97+26):
  cs.append(s.count(chr(i)))
  ct.append(t.count(chr(i)))
if sorted(cs) == sorted(ct):
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
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()
    D = defaultdict(str)
    for s, t in zip(S, T):
        if D[s] == "":
            D[s] = t
        if D[s] != t:
            print("No")
            exit()
    if len(set(D.keys())) != len(set(D.values())):
        print("No")
    else:
        print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

from collections import defaultdict

S = input()
T = input()

ctr_s = defaultdict(list)
ctr_t = defaultdict(list)
for i in range(len(S)):
    ctr_s[S[i]].append(i)
    ctr_t[T[i]].append(i)

ok = True
for key in ctr_s:
    char = T[ctr_s[key][0]]
    ok &= len(ctr_s[key]) == len(ctr_t[char])
    ok &= all(u == v for u, v in zip(ctr_s[key], ctr_t[char]))

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

Submission status: Accepted

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

n=len(s)

slis=[]

for i in range(n):
  if s[i] not in slis:
    slis.append(s[i])

tlis=[]

for i in range(n):
  if t[i] not in tlis:
    tlis.append(t[i])

snum=[]

for i in range(n):
  for j in range(len(slis)):
    if s[i]==slis[j]:
      snum.append(j)
      break

tnum=[]
for i in range(n):
  for j in range(len(tlis)):
    if t[i]==tlis[j]:
      tnum.append(j)


c=0
for i in range(n):
  if snum[i]!=tnum[i]:
    c+=1

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

Submission status: Accepted

Solution code:
# chokudaiをredcorderにするのはなんとなくできそうなきがするがなんでできないのだろうか
# c->r, r->c = rhokudai
# i->r, r->I = ihokudar
# たしかに出来なかった
# つまり目的の文字にできるのはせいぜい1回まで
# （2回目以降はそれより前に変化させた文字に影響が出る）
# なので、各文字の登場回数を出し、その数だけで比較する
s, t = list(input()), list(input())
sd, td = {}, {}
for sv in s:
    if sv not in sd:
        sd[sv] = 1
    else:
        sd[sv] += 1
for tv in t:
    if tv not in td:
        td[tv] = 1
    else:
        td[tv] += 1
ss, ts = sorted(sd.values()), sorted(td.values())
if ss == ts:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

sc = {}
tc = {}

for i in range(len(s)):
    if s[i] in sc:
        sc[s[i]].append(i)
    else:
        sc[s[i]] = [i]

    if t[i] in tc:
        tc[t[i]].append(i)
    else:
        tc[t[i]] = [i]

sc = list(sc.values())
tc = list(tc.values())

print("Yes" if sc == tc else "No")

Submission status: Accepted

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

s = [[] for i in range(26)]
t = [[] for i in range(26)]

for i in range(len(S)):
    s[ord(S[i])-97].append(i)
    t[ord(T[i])-97].append(i)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
t = input()

s_count = Counter(s)
t_count = Counter(t)
if sorted(s_count.values()) == sorted(t_count.values()): print("Yes")
else: print("No")

Submission status: Accepted

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

sl = list(s)
tl = list(t)

from collections import Counter
sc = Counter(sl)
tc = Counter(tl)

sp =[]
tp =[]

alp = "abcdefghijklmnopqrstuvwxyz"

for i in alp:
    sp.append(sc[i])
    tp.append(tc[i])

sps =sorted(sp)
tps = sorted(tp)

for i,j in zip (sps,tps):
    if i ==j:
        pass
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

import sys
dic_s={}
dic_t={}

for i in range(len(s)):
  a=dic_s.get(s[i],t[i])
  b=dic_t.get(t[i],s[i])
  if a!=t[i] or b!=s[i]:
    print("No")
    sys.exit()
  dic_s[s[i]]=t[i]
  dic_t[t[i]]=s[i]
print("Yes")

Submission status: Accepted

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

alph = ['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']

S_counter = []
T_counter = []
for i in alph:
    S_counter.append(S.count(i))
    T_counter.append(T.count(i))

S_counter.sort()
T_counter.sort()

if S_counter == T_counter:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

d = {}
use = set()
for si,ti in zip(s,t):
    if(si in d):
        if(ti != d[si]):
            print('No')
            exit()
    else:
        if(ti in use):
            print('No')
            exit()
        d[si] = ti
        use.add(ti)

print('Yes')

Submission status: Accepted

Solution code:
from collections import defaultdict

S = input()
T = input()

dictS = defaultdict(int)
dictT = defaultdict(int)
dictS[S[0]] = dictT[T[0]] = 1
n = 2

for i in range(1, len(S)):
    if dictS[S[i]] == dictT[T[i]]:
        if dictS[S[i]] == 0:
            dictS[S[i]] = dictT[T[i]] = n
            n += 1
    else:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
import collections 
s = input()
t = input()
sc = sorted(collections.Counter(s).values())
tc = sorted(collections.Counter(t).values())


for i in range(len(sc)):
  if sc[i] != tc[i]:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
from collections import Counter

S=list(input())
T=list(input())
a=Counter(S).most_common()
b=Counter(T).most_common()
for i in range(len(a)):
  if a[i][1]!=b[i][1]:
    print('No')
    exit()
else:
  print('Yes')

Submission status: Accepted

Solution code:
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    s = read_str()
    t = read_str()

    s_lis = sorted(Counter(s).values())
    t_lis = sorted(Counter(t).values())
    
    if s_lis == t_lis:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    Main()

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
t = input()
#文字の順番入れ替えは可能
#文字の個数は増やせない
#結局はaabbbなら2,3になる
#abcdbならa:1,b:2,c:1,d:1
s_dict = Counter(s)
t_dict = Counter(t)
s_val = list(s_dict.values())
t_val = list(t_dict.values())
s_val.sort()
t_val.sort()
if s_val == t_val:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

dict_S={}
dict_T={}

for x, y in zip(S, T):
    if x not in dict_S:
        dict_S[x] = y
    else:
        if dict_S[x] != y:
            print("No")
            exit()

    if y not in dict_T:
        dict_T[y] = x
    else:
        if dict_T[y] != x:
            print("No")
            exit()


print("Yes")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
from collections import Counter

s = input()
t = input()

c1 = Counter(s).most_common()
c2 = Counter(t).most_common()

for x, y in zip(c1, c2):
    if x[1] != y[1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
from collections import Counter

s = input()
t = input()
# sとtの文字列をカウントして昇順にソート
ss = sorted(Counter(s).values())
st = sorted(Counter(t).values())
# アルファベットの種類数と要素数が同じならYes
print("Yes") if ss == st else print("No")

Submission status: Accepted

Solution code:
s=input()
t=input()
sset=set()
tset=set()
j=1
alp={}
ds=[0]*len(s)
for i in range(len(s)):
  if not s[i] in sset:
    alp[s[i]]=j
    ds[i]=j
    sset.add(s[i])
    j+=1
  else:
    ds[i]=alp[s[i]]
j=1
alp={}
dt=[0]*len(t)
for i in range(len(t)):
  if not t[i] in tset:
    alp[t[i]]=j
    dt[i]=j
    tset.add(t[i])
    j+=1
  else:
    dt[i]=alp[t[i]]
for i in range(len(s)):
  if ds[i]!=dt[i]:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
"""
必要十分条件
１）Sの中の同じ文字が、Tの別の文字に対応していない
２）Tの中の同じ文字が、Sの別の文字に対応していない
"""

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')

Submission status: Accepted

Solution code:
S = input()
T = input()
s = sorted(map(S.count, set(S)))
t = sorted(map(T.count, set(T)))
print("Yes" if(s == t) else "No")

Submission status: Accepted

Solution code:
def solve():
    S=input()
    n=len(S)
    S1=[1]
    k=1
    for i in range(1,n):
        if S[i] not in S[:i]:
            k+=1
            S1.append(k)
        else:
            num=S1[S.find(S[i])]
            S1.append(num)
    return S1

S1=solve()
T1=solve()

if S1==T1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s = input()
t = input()
sl = len(s)
ss = ""
used = [False]*26
cnt = 0
for i in range(sl):
    if used[(ord(s[i])-97)%26]:
        ss += str(used[(ord(s[i])-97)%26])
    else:
        cnt += 1
        ss += str(cnt)
        used[(ord(s[i])-97)%26] = cnt

used = [False]*26
tt = ""
cnt = 0
for i in range(sl):
    if used[(ord(t[i])-97)%26]:
        tt += str(used[(ord(t[i])-97)%26])
    else:
        cnt += 1
        tt += str(cnt)
        used[(ord(t[i])-97)%26] = cnt

if ss==tt:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def char_list(s):
    l = [0] * 26
    for x in s:
        i = ord(x) - ord("a")
        l[i] += 1
    l.sort()
    return l

l1 = char_list(s)
l2 = char_list(t)

if l1 == l2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import defaultdict
s = input()
t = input()
n = len(s)

d = defaultdict(str)
# ダメな場合
# 1. 同じtが違うsに対応
# 2. 同じsが違うtに対応
for i in range(n):
    if d[t[i]] == "":
        d[t[i]] = s[i]
    elif d[t[i]] != s[i]:
        print("No")
        exit()
d.clear()
for i in range(n):
    if d[s[i]] == "":
        d[s[i]] = t[i]
    elif d[s[i]] != t[i]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
S=input()
T=input()
#条件は、SとTで、同じ文字が同じ場所に同数存在していること
d={}
#used=set()
for (s,t) in zip(S,T):
    try:
        if d[s]!=t:
            print("No")
            exit()
    except KeyError:
        #sとtの対応関係を記録
        d[s]=t

v=d.values() 
if len(v)!=len(set(v)):
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
S = input()
T = input()
S_cnt = sorted(S.count(c) for c in set(S))
T_cnt = sorted(T.count(c) for c in set(T))
print("Yes") if S_cnt == T_cnt else print("No")

Submission status: Accepted

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

trans_dict = {}

for i in range(len(S)):
    s = S[i]
    t = T[i]

    if s in trans_dict:
        if not trans_dict[s] == t:
            print('No')
            exit()
    else:
        trans_dict[s] = t

if len(trans_dict.values()) == len(set(trans_dict.values())):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter
S = list(input())
T = list(input())
change = [-1]*27
ans = "Yes"
for i in range(len(S)):
    s = ord(S[i])-97
    if S[i] == T[i]:
        change[s] = s
    elif change[s] == -1:
        change[s] = ord(T[i])-97
    else:
        t = ord(T[i])-97
        if change[s] != t:
            ans = "No"
            break
change=Counter(change)
del change[-1]
for i in change.values():
    if i==1:
        continue
    else:
        ans="No"
print(ans)

Submission status: Accepted

Solution code:
def main():
    from string import ascii_lowercase
    S = input()
    T = input()

    dic1 = {a: set() for a in ascii_lowercase}
    dic2 = {a: set() for a in ascii_lowercase}
    for s, t in zip(S, T):
        dic1[s].add(t)
        dic2[t].add(s)
    if all(len(s) <= 1 for s in dic1.values()) and\
            all(len(s) <= 1 for s in dic2.values()):
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input().strip()
T = input().strip()
N = len(S)
C = {}
D = {}
flag = 0
for i in range(N):
    if S[i] not in C:
        C[S[i]] = T[i]
    elif C[S[i]]!=T[i]:
        flag = 1
        break
    if T[i] not in D:
        D[T[i]] = S[i]
    elif D[T[i]] != S[i]:
        flag = 1
        break
if flag==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
s = input()
t = input()
alp =list("abcdefghijklmnopqrstuvwxyz")
sl = [0] * 26
tl = [0] * 26
for j in range(26):
        sl[j] = s.count(alp[j])
for j in range(26):
        tl[j] = t.count(alp[j])
sl.sort()
tl.sort()
if(sl == tl):
    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 fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
dics = defaultdict(str)
dict = defaultdict(str)
s = input()
t = input()
for i in range(len(s)):
    if dics[s[i]]:
        if dics[s[i]] == t[i]:
            pass
        else:
            print('No')
            exit()
    else:
        dics[s[i]] = t[i]
    if dict[t[i]]:
        if dict[t[i]] == s[i]:
            pass
        else:
            print('No')
            exit()
    else:
        dict[t[i]] = s[i]
print('Yes')

Submission status: Accepted

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

from collections import Counter
cs = Counter(s)
ct = Counter(t)

cs = list(cs.values())
ct = list(ct.values())

cs.sort()
ct.sort()

if cs == ct:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(S, T):
    d = dict()
    for i in range(len(S)):
        if S[i] != T[i]:
            if T[i] not in d:
                d[T[i]] = True
                S = ''.join([T[i] if s == S[i] else S[i] if s == T[i] else s for s in S])
            else:
                return False
    if S == T:
        return True
    return False

if __name__ == '__main__':
    input = sys.stdin.readline
    S = input().rstrip()
    T = input().rstrip()
    ans = main(S, T)
    print('Yes' if ans else 'No')

Submission status: Accepted

Solution code:
from collections import Counter
s = Counter(input())
t = Counter(input())

ans = "Yes"
for x,y in zip(s.items(), t.items()):
    if x[1] != y[1]:
        ans = "No"
print(ans)

Submission status: Accepted

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

d = {}
for si,ti in zip(s,t):
    if not si in d:
        d[si] = ti
    else:
        if d[si] != ti:
            print('No')
            break
else:
    sset = set()
    for v in d.values():
        if v in sset:
            print('No')
            break
        sset.add(v)
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import sys
s = list(input())
t = list(input())
a = [-1 for _ in range(26)]
b = [-1 for _ in range(26)]

for i in range(len(s)):
    num0, num1 = a[ord(s[i])-97], b[ord(t[i])-97]
    if num0 >= 0:
        if chr(num0+97) != t[i]:
            print('No')
            sys.exit()
    else:
        a[ord(s[i])-97] = ord(t[i])-97
        
    if num1 >= 0:
        if chr(num1+97) != s[i]:
            print('No')
            sys.exit()
    else:
        b[ord(t[i])-97] = ord(s[i])-97
            
print('Yes')

Submission status: Accepted

Solution code:
import sys


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


def main():
    S = input()
    T = input()
    dictS =dict()
    dictT =dict()

    for i in range(len(S)):
        if S[i] in dictS:
            if dictS[S[i]] !=T[i]:
                print("No")
                exit()
        else:
            dictS[S[i]] =T[i]

        if T[i] in dictT:
            if dictT[T[i]] !=S[i]:
                print("No")
                exit()
        else:
            dictT[T[i]] =S[i]

    print("Yes")



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline


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

    c_S = Counter(S)
    c_T = Counter(T)
    count_S = list(c_S.values())
    count_T = list(c_T.values())
    count_S.sort()
    count_T.sort()
    is_same = True
    for s, t in zip(count_S, count_T):
        if s != t:
            is_same = False
            break

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S=input()
T=input()
from collections import*
cs=Counter(S)
ct=Counter(T)
csv=sorted(cs.values())
ctv=sorted(ct.values())
print('YNeos'[csv!=ctv::2])

Submission status: Accepted

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

s_map = [[] for i in range(26)]
t_map = [[] for i in range(26)]
n = len(s)

for i in range(n):
    si = ord(s[i]) - ord("a")
    ti = ord(t[i]) - ord("a")
    
    s_map[si].append(i)
    t_map[ti].append(i)

s_map = sorted(s_map)
t_map = sorted(t_map)

if s_map == t_map:
    print("Yes")
else:
    print("No")
# print(s_map)
# print(t_map)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def solve(S, T):
    d = dict()
    for s, t in zip(S, T):
        if s in d and d[s] != t:
            return False
        else:
            d[s] = t

    return True


def main():
    S = readline().strip()
    T = readline().strip()

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

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

s = Counter(S)
t = Counter(T)

if sorted(s.values()) == sorted(t.values()):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
from collections import Counter
s = list(input())
t = list(input())

s_count = Counter(s)
t_count = Counter(t)

# s,tそれぞれの各文字の出現回数が同じであれば一致させられる
if sorted(s_count.values()) == sorted(t_count.values()): print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
s=input()
t=input()
n=len(s)
f=0
a=[[] for i in range(26)]
for i in range(n):
    
    if len(a[ord(s[i])-97])==0:
        a[ord(s[i])-97].append(t[i])
    else:
        if a[ord(s[i])-97][0]!=t[i]:
            f=1
x=[a[i][0] for i in range(26) if len(a[i])==1]
if len(x)!=len(set(x)):
    f=1
print("Yes" if f==0 else "No")

Submission status: Accepted

Solution code:
import collections
S = list(input())
T = list(input())
 
cntS = collections.Counter(S)
cntT = collections.Counter(T)
 
if len(cntS) != len(cntT):
    print('No')
    exit()
else:
    valS = list(cntS.values())
    valT = list(cntT.values())

    if valS != valT:
            print('No')
            exit()
print('Yes')

Submission status: Accepted

Solution code:
s = input()
t = input()
d = []
for l in [s, t]:
    ptr = 0
    dct = dict()
    for c in l:
        if c not in dct.keys():
            dct[c] = chr(ord("A")+ptr)
            ptr += 1
    d.append([dct[c] for c in l])

print("Yes" if "".join(d[0]) == "".join(d[1]) else "No")

Submission status: Accepted

Solution code:
s=list(input())
t=list(input())
n=len(s)
a=[s.count(chr(97+i)) for i in range(26)]
b=[t.count(chr(97+i)) for i in range(26)]
if all(a[ord(s[i])-97]==b[ord(t[i])-97] for i in range(n)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
x = lambda : sorted(Counter(input()).values())
print('YNeos'[x()!=x()::2])

Submission status: Accepted

Solution code:
s=[ord(c) for c in input()]
t=[ord(c) for c in input()]
n=len(s)
st=[(s[i],t[i]) for i in range(n)]
st=sorted(st,key=lambda x:x[0])
s=[c for c,_ in st]
t=[c for _,c in st]

for i in range(n-1):
    if (s[i]==s[i+1]) ^ (t[i]==t[i+1]):
        print('No')
        exit(0)

st=sorted(st,key=lambda x:x[1])
s=[c for c,_ in st]
t=[c for _,c in st]

for i in range(n-1):
    if (s[i]==s[i+1]) ^ (t[i]==t[i+1]):
        print('No')
        exit(0)


print('Yes')

Submission status: Accepted

Solution code:
def p(S):
    D={}
    for i in range(len(S)):
        a=S[i]
        if a in D:
            D[a].add(i)
        else:
            D[a]={i}
    return D
S=input()
T=input()

A=sorted(p(S).values())
B=sorted(p(T).values())

if A==B:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    s = input()
    t = input()
    S = sorted(map(s.count, set(s)))
    T = sorted(map(t.count, set(t)))
    print("Yes" if S == T else "No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

s = input()
t = input()

a = Counter(s)
b = Counter(t)

c = list(a.values())
d = list(b.values())

print('Yes') if c == d else print('No')

Submission status: Accepted

Solution code:
S=input()
T=input()
d=[[] for i in range(26)]
for i,c in enumerate(S):
    d[ord(c)-ord('a')].append(i)
d2=[[]for i in range(26)]
for i,c in enumerate(T):
    d2[ord(c)-ord('a')].append(i)
print(['No','Yes'][set((tuple(x) for x in d))==set((tuple(x) for x in d2))])

Submission status: Accepted

Solution code:
s=input()
t=input()
ar1=[0]*26
ar2=[0]*26
for i in s:
    ar1[ord(i)-97]+=1
for i in t:
    ar2[ord(i)-97]+=1
ar1.sort()
ar2.sort()
if ar1==ar2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def make_map(X):
    X = list(map(lambda x: ord(x) - ord("a"), X))
    s = [-1]*26
    res = [0]+[-1]*(len(X)-1)
    cnt = 0
    for i, x in enumerate(X):
        if s[x] == -1:
            s[x] = res[i] = cnt
            cnt += 1
        else:
            res[i] = s[x]
    return res
print("Yes" if make_map(input())==make_map(input()) else "No")

Submission status: Accepted

Solution code:
def ch(x):
    return ord(x)-ord("a")
def dch(x):
    return chr(x+ord("a"))

S = input().rstrip()
T = input().rstrip()

s0 = S[0]
cnt = 1
A1 = []
P = [-1]*26
k=0
for s in S[1:]:
    if s==s0:
        cnt += 1
    else:
        if P[ch(s0)] == -1:
            P[ch(s0)] = k
            k += 1
            A1.append((P[ch(s0)], cnt))
        else:
            A1.append((P[ch(s0)], cnt))
        cnt = 1
    s0 = s
if cnt == 1:
    if P[ch(s0)] == -1:
        P[ch(s0)] = k
        k += 1
        A1.append((P[ch(s0)], cnt))
    else:
        A1.append((P[ch(s0)], cnt))

t0 = T[0]
cnt = 1
B1 = []
P = [-1]*26
k=0
for t in T[1:]:
    if t==t0:
        cnt += 1
    else:
        if P[ch(t0)] == -1:
            P[ch(t0)] = k
            k += 1
            B1.append((P[ch(t0)], cnt))
        else:
            B1.append((P[ch(t0)], cnt))
        cnt = 1
    t0 = t
if cnt == 1:
    if P[ch(t0)] == -1:
        P[ch(t0)] = k
        k += 1
        B1.append((P[ch(t0)], cnt))
    else:
        B1.append((P[ch(t0)], cnt))

if A1==B1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

d = [None]*26
flag = True
for s,t in zip(S,T):
    s = ord(s)-ord('a')
    t = ord(t)-ord('a')
    if d[s] is None:
        d[s] = t
    elif d[s] != t:
        flag = False
        break

if not flag:
    print('No')
elif len(set(v for v in d if v is not None)) != sum(int(v is not None) for v in d):
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50

def create_new_arr(DICT, SEQ):
    new_seq = ''
    next_id = 0
    for s in SEQ:
        if s not in DICT:
            DICT[s] = str(next_id)
            next_id += 1
        new_seq += DICT[s]
    return new_seq

def run():
    S, T = input(), input()
    s_dic = {}
    t_dic = {}

    new_S = create_new_arr(s_dic, S)
    new_T = create_new_arr(t_dic, T)

    if new_S == new_T:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
s = input()
t = input()
n = len(s)
jisho1 = {}
jisho2 = {}


def ng():
    print("No")
    exit()


for i in range(n):
    if s[i] in jisho1:
        if jisho1[s[i]] != t[i]:
            ng()
    else:
        jisho1[s[i]] = t[i]
    if t[i] in jisho2:
        if jisho2[t[i]] != s[i]:
            ng()
    else:
        jisho2[t[i]] = s[i]
print("Yes")

Submission status: Accepted

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

chars = "abcdefghijklmnopqrstuvwxyz"
c2n = {chars[i]: i for i in range(26)}
RS = [-1]*26
RT = [-1]*26
N = len(S)
flag = True
for i in range(N):
    if RS[c2n[S[i]]] >= 0:
        if RS[c2n[S[i]]] != c2n[T[i]]:
            flag = False
            break
    if RT[c2n[T[i]]] >= 0:
        if RT[c2n[T[i]]] != c2n[S[i]]:
            flag = False
            break
    if RS[c2n[S[i]]] < 0:
        RS[c2n[S[i]]] = c2n[T[i]]
    if RT[c2n[T[i]]] < 0:
        RT[c2n[T[i]]] = c2n[S[i]]
    
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter
s=Counter(list(input()))
t=Counter(list(input()))
s1,t1=sorted(list(s.values())),sorted(list(t.values()))
print("Yes" if s1==t1 else "No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[16]:


S = input()
T = input()


# In[20]:


mydict = {}
for i in range(len(S)):
    if S[i] in mydict:
        if T[i] != mydict[S[i]]:
            ans = "No"
            break
    else:
        mydict[S[i]] = T[i]
else:
    a = list(mydict.values())
    b = list(set(a))
    if len(b) != len(a):
        ans = "No"
    else:
        ans = "Yes"
print(ans)


# In[ ]:

Submission status: Accepted

Solution code:
S = input()
T = input()
N = len(S)
# SからTの変換
d1 = {}
# TからSの変換
d2 = {}

for i in range(N):
    if S[i] not in d1:
        d1[S[i]] = T[i]
    else:
        if d1[S[i]] != T[i]:
            print("No")
            exit()
        else:
            pass

    if T[i] not in d2:
        d2[T[i]] = S[i]
    else:
        if d2[T[i]] != S[i]:
            print("No")
            exit()
        else:
            pass
print("Yes")

Submission status: Accepted

Solution code:
s = input()
t = input()
memo = {}
ans = 'Yes'
for i in range(len(s)):
    if s[i] in memo:
        if t[i] != memo[s[i]]:
            ans = 'No'
            break
    else:
        memo[s[i]] = t[i]
a = list(memo.values())
b = list(set(a))
if len(b) != len(a):
    ans = 'No'
print(ans)