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=sorted(collections.Counter(input()).values())
t=sorted(collections.Counter(input()).values())
print("Yes" if s==t else "No")

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:
s=input()
t=input()
n=len(s)

dic={}
ans='Yes'
for i in range(n):
    if t[i] not in dic:
        dic[t[i]]=s[i]
    
    else:
        if dic[t[i]]==s[i]:
            continue
        else :
            ans='No'
            break
    
if len(dic)!=len(set(dic.values())):
    ans='No'
print(ans)

Submission status: Accepted

Solution code:
# S,Tのアルファベットが一対一で痴漢出来れば良い
import sys 
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
 
s = ns()
t = ns()

s_cnt = []
t_cnt = []

for alp in "abcdefghijklmnopqrstuvwxyz":
  s_cnt.append(s.count(alp))
  t_cnt.append(t.count(alp))

s_cnt.sort()
t_cnt.sort()

if s_cnt == t_cnt:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

dict_S_to_T = {}
dict_T_to_S = {}

for s, t in zip(S, T):
    if s not in dict_S_to_T.keys():
        dict_S_to_T[s] = t
    else:
        if dict_S_to_T[s] != t:
            print('No')
            exit()
    if t not in dict_T_to_S.keys():
        dict_T_to_S[t] = s
    else:
        if dict_T_to_S[t] != s:
            print('No')
            exit()

print('Yes')

Submission status: Accepted

Solution code:
from collections import Counter

S = str(input())
T = str(input())

s_counter = Counter(S)
t_counter = Counter(T)

# print(s_counter)
# print(t_counter)

dict_S_to_T = {}
dict_T_to_S = {}

for s, t in zip(S, T):
    if s not in dict_S_to_T.keys():
        dict_S_to_T[s] = t
    else:
        if dict_S_to_T[s] != t:
            print('No')
            exit()
    if t not in dict_T_to_S.keys():
        dict_T_to_S[t] = s
    else:
        if dict_T_to_S[t] != s:
            print('No')
            exit()

print('Yes')

Submission status: Accepted

Solution code:
import collections
S=input()
T=input()
tableS=collections.defaultdict(list)
tableT=collections.defaultdict(list)

for i in range(len(S)):
  tableS[S[i]].append(i)
  tableT[T[i]].append(i)
listS=tableS.values()
listT=tableT.values()

for x in listS:
  flag=False
  for y in listT:
    if x in y or x in listT:
      flag=True
      break
  if not flag:
    print("No")
    exit(0)
print("Yes")

Submission status: Accepted

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

dic = {}
for i in range(len(S)):
  s = S[i]
  t = T[i]
  if s in dic.keys():
    if dic[s] != t:
      print('No')
      exit()
  else:
    if t in dic.values():
      print('No')
      exit()
    else:
      dic[s] = t
print('Yes')

Submission status: Accepted

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

s_count = []
t_count = []
for i in "abcdefghijklmnopqrstuvwxyz":
    s_count.append(s.count(i))
    t_count.append(t.count(i))
print("Yes" if sorted(s_count) == sorted(t_count) else "No")

Submission status: Accepted

Solution code:
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

def getInputStr():
    inputNum = str(input())
    return inputNum

s = getInputStr()
t = getInputStr()


listS = []
listS = list(s)
listT = []
listT = list(t)

lim = len(listS)

onedic = {}
twodic = {}

flg = True

for i in range(lim):
    keyone = listS[i]
    keytwo = listT[i]

    if keyone not in onedic:
        onedic[keyone] = keytwo
    else:
        if onedic[keyone] != keytwo:
            flg = False
            break

    if keytwo not in twodic:
        twodic[keytwo] = keyone
    else:
        if twodic[keytwo] != keyone:
            flg = False
            break

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

Submission status: Accepted

Solution code:
S = input()
T = input()
N = len(S)
C_S = dict()
C_T = dict()
count_s = 0
count_t = 0
s_list = []
t_list = []
for i in range(N):
    if S[i] in C_S:
        C_S[S[i]] += 1
    else:
        C_S[S[i]] = 1
        count_s += 1
for i in range(N):
    if T[i] in C_T:
        C_T[T[i]] += 1
    else:
        C_T[T[i]] = 1
        count_t += 1
check = True
for skey in C_S.keys():
    s_list.append(C_S[skey])
for tkey in C_T.keys():
    t_list.append(C_T[tkey])
s_list.sort()
t_list.sort()

if count_s == count_t:
    for i in range(len(s_list)):
        if s_list[i] != t_list[i]:
            check = False
else:
    check = False

if check:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import os, sys, re, math

S = input()
T = input()

table = {}
flg = True
for i in range(len(S)):
	if S[i] in table.keys():
		if T[i] != table[S[i]]:
			flg = False
	else:
		if T[i] in table.values():
			flg = False
		else:
			table[S[i]] = T[i]
	if not flg:
		break

if flg:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
s = input()
t = input()
num_s ={}
num_t ={}
for i in range(len(s)):
    si = s[i]
    ti = t[i]
    if si in num_s:
        num_s[si] +=1
    else:
        num_s[si] =1
    if ti in num_t:
        num_t[ti] +=1
    else:
        num_t[ti] =1

values_s = list(num_s.values())
values_t = list(num_t.values())
values_s.sort()
values_t.sort()
if values_s==values_t:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

dic={}
for i in range(len(s)):
    if s[i] not in dic:
        dic.setdefault(s[i],t[i])
    else:
        if t[i]!=dic[s[i]]:
            print("No")
            exit()

dic={}
for i in range(len(t)):
    if t[i] not in dic:
        dic.setdefault(t[i],s[i])
    else:
        if s[i]!=dic[t[i]]:
            print("No")
            exit()
            
print("Yes")

Submission status: Accepted

Solution code:
from collections import Counter

S = Counter(list(input()))
T = Counter(list(input()))

flag = False
for s, t in zip(S.most_common(), T.most_common()):
    if s[1] != t[1]:
        flag = True
print('No' if flag else 'Yes')

Submission status: Accepted

Solution code:
S = raw_input()
T = raw_input()
d = dict()
d2 = dict()
ret = True
for s, t in zip(S, T):
    if s in d and d[s] != t:
        ret = False
        break
    if t in d2 and d2[t] != s:
        ret = False
        break
    d[s] = t
    d2[t] = s
        
print 'Yes' if ret else 'No'

Submission status: Accepted

Solution code:
aaa = input()
bbb = input()
d = {}
d_rev = {}
ans = 'Yes'
for a, b in zip(aaa, bbb):
  if (a in d and d.get(a) != b) or (b in d_rev and d_rev.get(b) != a):
    ans = 'No'
  d[a] = b
  d_rev[b] = a
print(ans)

Submission status: Accepted

Solution code:
import os, sys, re, math

S = input()
T = input()

sCount = [0] * 26
tCount = [0] * 26

for s in S:
    sCount[ord(s) - ord('a')] += 1
for t in T:
    tCount[ord(t) - ord('a')] += 1

sCount.sort()
tCount.sort()

print ('Yes' if sCount == tCount else 'No')

Submission status: Accepted

Solution code:
s = input()
t = input()
print("Yes" if len(set(s)) == len(set(t)) == len(set(zip(s, t))) else "No")

Submission status: Accepted

Solution code:
s = input()
t = input()
dct = dict()
 
bool =True
for a,b in zip(s,t):
    if a in dct and dct[a]!=b:
        bool =False
        break
    dct[a]=b
#print(dct)
#print(len(dct.values()))
#print(len(dct))
if len(dct.values())!=len(set(dct.values())):
    bool =False
print('Yes' if bool else 'No')

Submission status: Accepted

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

bool =True
for a,b in zip(s,t):
    if a in dct and dct[a]!=b:
        bool =False
        break
    dct[a]=b
#print(dct)
#print(len(dct.values()))
#print(len(dct))
a =dct.values()
if len(a)!=len(set(a)):
    bool =False
print('Yes' if bool else 'No')

Submission status: Accepted

Solution code:
S,T = input(),input()
 
convert = dict()
 
bl = True
for s,t in zip(S,T):
  if s in convert and convert[s] != t:
    bl = False
    break
  convert[s] = t
 
# 変換先の重複チェック
after = convert.values()
if len(after) != len(set(after)):
  bl = False
 
print('Yes' if bl else 'No')

Submission status: Accepted

Solution code:
def test():
    s = input()
    t = input()
    dict1,dict2 = {},{}
    for i,j in zip(s,t):
        if i in dict1:
            if dict1[i] != j:
                print("No")
                return
        else:
            dict1[i] = j
        if j in dict2:
            if dict2[j] != i:
                print("No")
                return
        else:
            dict2[j] = i
    print("Yes")


if __name__ == "__main__":
    test()

Submission status: Accepted

Solution code:
# C - String Transformation
import collections
S = str(input())
T = str(input())

S1 = sorted(collections.Counter(S).values())
T1 = sorted(collections.Counter(T).values())

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

Submission status: Accepted

Solution code:
from collections import Counter

s = input()
t = input()

S = sorted(Counter(s).values())
T = sorted(Counter(t).values())

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

Submission status: Accepted

Solution code:
import sys 
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()

s = ns()
t = ns()
s_cnt = []
t_cnt = []
for alp in "abcdefghijklmnopqrstuvwxyz":
  s_cnt.append(s.count(alp))
  t_cnt.append(t.count(alp))
s_cnt.sort()
t_cnt.sort()
if s_cnt == t_cnt:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
from collections import Counter as cnt
fnc = lambda: cnt(cnt(input()).values())
print("Yes" if fnc() == fnc() else "No")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from collections import Counter
    s=Counter(input()).most_common()
    t=Counter(input()).most_common()
    n=len(s)
    print("Yes" if all(s[i][1]==t[i][1] for i in range(n)) else "No")
resolve()

Submission status: Accepted

Solution code:
S=input()
T=input()
N=len(S)
def char2num(a):
  temp='abcdefghijklmnopqrstuvwxyz'
  i=0
  while temp[i]!=a:
    i+=1
  return i

s2t=[-1]*26
t2s=[-1]*26
for i in range(N):
  snum=char2num(S[i])
  tnum=char2num(T[i])
  if s2t[snum]>=0 or t2s[tnum]>=0:
    if s2t[snum]!=tnum or t2s[tnum]!=snum:
      print('No')
      exit()
  else:
    s2t[snum]=tnum
    t2s[tnum]=snum
    
print('Yes')

Submission status: Accepted

Solution code:
from  collections import Counter

S = input()
T = input()

s_counter = Counter(S)
t_counter = Counter(T)

if sorted(s_counter.values()) == sorted(t_counter.values()):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

sd = dict()
td = dict()
ans = True
for s, t in zip(S, T):
    if s not in sd:
        sd[s] = t
    else:
        if sd[s] != t:
            ans = False
            break

    if t not in td:
        td[t] = s
    else:
        if td[t] != s:
            ans = False
            break

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

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.readline


def main():
    S = input()[:-1]
    T = input()[:-1]

    ds = defaultdict(int)
    dt = defaultdict(int)
    for i in range(len(S)):
        ds[S[i:i+1]] += 1
        dt[T[i:i+1]] += 1
    
    ds = sorted(ds.items(), key=lambda x: x[1])
    dt = sorted(dt.items(), key=lambda x: x[1])

    if len(ds)!=len(dt):
        print('No')
        return
    for i in range(len(ds)):
        if ds[i][1] != dt[i][1]:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
S = list(input())
T = list(input())
l = len(S)
ds = defaultdict(str)
dt = defaultdict(str)
for i in range(l):
    if ds[S[i]] == "":
        ds[S[i]] = T[i]
    elif ds[S[i]] == T[i]:
        pass
    else:
        print('No')
        exit()
    if dt[T[i]] == "":
        dt[T[i]] = S[i]
    elif dt[T[i]] == S[i]:
        pass
    else:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
t = input()
convert_dict = {}
count_list = []
count = {}

for i in range(len(s)):
    if t[i] not in convert_dict.keys():
        convert_dict[t[i]] = s[i]

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

for i in convert_dict.values():
    count_list.append(i)

count = Counter(count_list)

if max(count.values()) > 1:
    print("No")

else:
    print("Yes")