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:
from sys import stdin
from collections import Counter

input = stdin.readline

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


def main():
    C1 = sorted(Counter(S).values())
    C2 = sorted(Counter(T).values())

    print("Yes" if C1 == C2 else "No")
    return


main()

Submission status: Accepted

Solution code:
from sys import stdin
from collections import Counter

input = stdin.readline

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


def main():
    C1 = Counter(S).most_common()
    C2 = Counter(T).most_common()

    if len(C1) != len(C2):
        print("No")
        return

    flg = True
    for i in range(len(C1)):
        if C1[i][1] != C2[i][1]:
            flg = False

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


main()

Submission status: Accepted

Solution code:
#from sys import stdin
from collections import Counter
from operator import itemgetter

#input = stdin.readline

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


def main():
    C1 = Counter(S).most_common()
    C2 = Counter(T).most_common()

    if len(C1) != len(C2):
        print("No")
        return

    flg = True
    for i in range(len(C1)):
        if C1[i][1] != C2[i][1]:
            flg = False

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


main()

Submission status: Accepted

Solution code:
input = open(0).read
S, T = input().split()


def main():
    C1 = [None] * (ord('z') - ord('a') + 1)
    C2 = [None] * (ord('z') - ord('a') + 1)

    flg = True

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

        if C1[c1] or C2[c2]:
            if c1 != C2[c2] or c2 != C1[c1]:
                flg = False
                break

        C1[c1] = c2
        C2[c2] = c1

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


main()

Submission status: Accepted

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

d1 = dict()
d2 = dict()
L = len(S)
for i in range(L):
    s = S[i]
    t = T[i]
    if s in d1 and d1[s] != t:
        print("No")
        exit()
    else:
        d1[s] = t
    if t in d2 and d2[t] != s:
        print("No")
        exit()
    else:
        d2[t] = s
print("Yes")

Submission status: Accepted

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

ans = 'Yes'

d = dict([])
for i,s in enumerate(S):
    t = T[i]
    try:
        if d[s] != t:
            ans = 'No'
            break
    except:
        d[s] = t

d = dict([])
for i,t in enumerate(T):
    if ans == 'No':
        break
    s = S[i]
    try:
        if d[t] != s:
            ans = 'No'
            break
    except:
        d[t] = s
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

s_dict, t_dict = {}, {}

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

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

print("Yes")

Submission status: Accepted

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


from collections import Counter


s_dict, t_dict = {}, {}

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

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

print("Yes")

Submission status: Accepted

Solution code:
def ans():
  S = input()
  T = input()
  s = []
  t = []
  for alp in "abcdefghijklmnopqrstuvwxyz":
    s.append(S.count(alp))
    t.append(T.count(alp))
  if(sorted(s) == sorted(t)):
    print("Yes")
  else:
    print("No")
ans()

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

S=input()
T=input()

def n2l(s):
    seen = {}
    ret = []
    idx = 0
    for ch in s:
        if ch not in seen:
            seen[ch] = idx
            idx += 1
        ret.append(seen[ch])
    return ret

yn(n2l(S)==n2l(T))

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

S=input()
T=input()

dT = dict()
dS = dict()

for i,t in enumerate(T):
    if t not in dT:
        dT[t] = [i]
    else:
        dT[t].append(i)
for i,s in enumerate(S):
    if s not in dS:
        dS[s] = [i]
    else:
        dS[s].append(i)

def ans():
    for c in map(chr,range(ord('a'),ord('z')+1)):
        if c in dT:
            res = S[dT[c][0]]
            for i in dT[c]:
                if res != S[i]:
                    return 0
    for c in map(chr,range(ord('a'),ord('z')+1)):
        if c in dS:
            res = T[dS[c][0]]
            for i in dS[c]:
                if res != T[i]:
                    return 0
    return 1

yn(ans())

Submission status: Accepted

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

ls = [0] * 26
lt = [0] * 26
for s in S:
    ls[ord(s) - 97] += 1
for t in T:
    lt[ord(t) - 97] += 1
ls.sort()
lt.sort()
if ls == lt:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:

S = input()
T = input()
start = [-1] * 26
goal = [-1] * 26

for i in range(len(S)):
    start_index = ord(S[i]) - ord("a")
    goal_index = ord(T[i]) - ord("a")
    if start[start_index] != -1 or goal[goal_index] != -1:
        if start[start_index] != goal_index or goal[goal_index] != start_index:
            print("No")
            exit()
        else:
            continue
    start[start_index] = goal_index
    goal[goal_index] = start_index
print("Yes")
exit()
print(start, "\n", goal)


def transform_char(s):
    return chr(s+ord("a"))


print(list(map(transform_char, start)))

Submission status: Accepted

Solution code:
def string_transformation(S: int, T: int) -> bool:
    ds = {}
    dt = {}
    for s, t in zip(S, T):
        if s in ds:
            if ds[s] != t:
                return False
        else:
            ds[s] = t

        if t in dt:
            if dt[t] != s:
                return False
        else:
            dt[t] = s

    return True


if __name__ == "__main__":
    S = input()
    T = input()
    ans = string_transformation(S, T)
    print('Yes' if ans else 'No')

Submission status: Accepted

Solution code:
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:
		if start[a] != b or goal[b] != a:
			print('No')
			exit()
	start[a] = b
	goal[b] = a
print('Yes')

Submission status: Accepted

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


def f(s):
    l=[]
    a="abcdefghijklmnopqrstuvwxyz"
    r=""
    for i in range(len(s)):
        if s[i] in l:
            for j in range(len(l)):
                if s[i]==l[j]:
                    r+=a[j]
        else:
            r+=a[len(l)]
            l.append(s[i])
    return r

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

Submission status: Accepted

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

S, T = input(), input()
nS = len(S)

dS, dT = {}, {}
for i in range(nS):
    if not S[i] in dS:
        dS[S[i]] = T[i]
    elif not dS[S[i]] == T[i]:
        print("No")
        exit()

    if not T[i] in dT:
        dT[T[i]] = S[i]
    elif not dT[T[i]] == S[i]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
S = input()
T = input()
d_st = {}
d_ts = {}
flag = True
for i in range(len(S)):
    if S[i] not in d_st:
        d_st[S[i]] = T[i]
    else:
        if d_st[S[i]] != T[i]:
            flag = False
            break
    if T[i] not in d_ts:
        d_ts[T[i]] = S[i]
    else:
        if d_ts[T[i]] != S[i]:
            flag = False
            break
    
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import collections
S = input()
T = input()
s_alp = [chr(i) for i in range(97, 97+26)]
s_ = ['']*26
t_alp = [chr(i) for i in range(97, 97+26)]
t_ = ['']*26
for i in range(len(S)):
  if s_[s_alp.index(S[i])] == '':
    s_[s_alp.index(S[i])] = T[i]
  else:
    if s_[s_alp.index(S[i])] != T[i]:
      print('No')
      break
  if t_[t_alp.index(T[i])] == '':
    t_[t_alp.index(T[i])] = S[i]
  else:
    if t_[t_alp.index(T[i])] != S[i]:
      print('No')
      break
else:
  print('Yes')

Submission status: Accepted

Solution code:
#S->Tができるなら逆も可
#アルファベットが1対1に対応していたら絶対に作れる
#1対多または多対1はだめ

S = input()
T = input()
alpS = [-1 for i in range(26)] #a:0, z:25
alpT = [-1 for i in range(26)]
lenS = len(S)
flg = 1
#Sの1つのアルファベットがTの複数のアルファベットに対応していないか調べる
for i in range(lenS):
    alp = ord(S[i]) - 97
    if alpS[alp] == -1:
        alpS[alp] = ord(T[i]) - 97
    else:
        if alpS[alp] != ord(T[i]) - 97:
            flg = 0
            break
#Sの2種類以上のアルファベットがTの同じアルファベットに対応していないか調べる
for i in range(lenS):
    alp = ord(T[i]) - 97
    if alpT[alp] == -1:
        alpT[alp] = ord(S[i]) - 97
    else:
        if alpT[alp] != ord(S[i]) - 97:
            flg = 0
            break

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

Submission status: Accepted

Solution code:
s=[0 for _ in range(26)]
t=[0 for _ in range(26)]
S=input()
T=input()

for i in range(len(S)):
    s[ord(S[i])-ord('a')]+=1
    t[ord(T[i])-ord('a')]+=1

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

Submission status: Accepted

Solution code:
from collections import defaultdict
S=input()
T=input()
d=defaultdict(list)
e=defaultdict(list)
for i in range(len(S)):
  d[S[i]].append(i)
  e[T[i]].append(i)
print("Yes" if all(item in e.values() for item in d.values()) else "No")

Submission status: Accepted

Solution code:
S = input()
T = input()
trans_dict = dict()
trans_dict_ = dict()
flg = 0
for s, t in zip(S, T):
    if trans_dict.get(s) is None:
        trans_dict[s] = t
    elif trans_dict.get(s) == t:
        continue
    else:
        flg = 1
        break
    if trans_dict_.get(t) is None:
        trans_dict_[t] = s
    elif trans_dict.get(t) == s:
        continue
    else:
        flg = 1
        break
if flg == 1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
S = input()
T = input()
def count(string):
    Ans =[0]*len(string)
    Alpha = [0]*26
    c = 0
    for st in string:
        if(Alpha[ord(st)-97] == 0):
            Alpha[ord(st)-97] = c
            Ans[c] = c
        elif(Alpha[ord(st)-97] != 0):
            Ans[c] = Alpha[ord(st)-97]
    
        c += 1
    return Ans

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S,T=input(),input()
N=len(S)
link_a={}
link_b={}

for i in range(N):
    if  T[i] in link_a:
        if link_a[T[i]] == S[i]:
            continue
        else:
            print('No')
            exit()
    else:
        link_a[T[i]]=S[i]

for i in range(N):
    if  S[i] in link_b:
        if link_b[S[i]] == T[i]:
            continue
        else:
            print('No')
            exit()
    else:
        link_b[S[i]]=T[i]
print('Yes')

Submission status: Accepted

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

import re
def findall(string,s):
    return [m.start() for m in re.finditer(s, string)]

from collections import Counter
C1 = Counter(T).most_common()
C2 = Counter(S).most_common()

ans = 'Yes'

for c in C1:
    if c[1] >= 2:
        # import pdb;pdb.set_trace()
        ls = findall(T,c[0])
        s_set = set()
        for num in ls:
            s_set.add(S[num])
        if len(s_set) > 1:
            ans = 'No'
            
for c in C2:
    if c[1] >= 2:
        # import pdb;pdb.set_trace()
        ls = findall(S,c[0])
        s_set = set()
        for num in ls:
            s_set.add(T[num])
        if len(s_set) > 1:
            ans = 'No'
            
print(ans)

Submission status: Accepted

Solution code:
s=[0 for _ in range(26)]
t=[0 for _ in range(26)]
S=input()
T=input()

for i in range(len(S)):
  s[ord(S[i])-ord('a')]+=1
  t[ord(T[i])-ord('a')]+=1

s.sort()
t.sort()
print('Yes' if s==t else 'No')

Submission status: Accepted

Solution code:
def check(s,t):
    if len(s) != len(t):
        return False
    l = len(s)
    s_t = {}
    t_s = {}
    for i in range(l):
        if s[i] in s_t.keys():
            if s_t[s[i]] != t[i]:
                return False
        else:
            s_t[s[i]] = t[i]
        if t[i] in t_s.keys():
            if t_s[t[i]] != s[i]:
                return False
        else:
            t_s[t[i]] = s[i]
    return True

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

Submission status: Accepted

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

R = {chr(i) : -1 for i in range(97, 97 + 26)}
Rd = {chr(i) : -1 for i in range(97, 97 + 26)}

def check(i):
  ret = True
  if R[S[i]] >= 0 and R[S[i]] != ord(T[i]):
    ret = False
  if Rd[T[i]] >= 0 and Rd[T[i]] != ord(S[i]):
    ret = False
  if R[S[i]] < 0:
    R[S[i]] = ord(T[i])
  if Rd[T[i]] < 0:
    Rd[T[i]] = ord(S[i])
  return ret

ans = "Yes"
for i in range(len(S)):
  if not check(i):
    ans = "No"
    break
print(ans)

Submission status: Accepted

Solution code:
s=input()
t=input()
l=[]
m=[]
for i in range(len(s)):
    l.append(s[i])
    m.append(t[i])
l.sort()
m.sort()
li=[1]
mi=[1]
i=1
while i<len(s):
    if l[i]==l[i-1]:
        li[-1]+=1
    else:
        li.append(1)
    if m[i]==m[i-1]:
        mi[-1]+=1
    else:
        mi.append(1)
    i+=1
li.sort()
mi.sort()
print("Yes" if li==mi else "No")

Submission status: Accepted

Solution code:
def solve(string):
    s, t = string.split()

    c_s = sorted([s.count(_c) for _c in set(s)])
    c_t = sorted([t.count(_c) for _c in set(t)])

    if c_s == c_t:
        return "Yes"
    else:
        return "No"


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
def check(S, T):
    n = len(S)
    m = {}
    d = {}
    for i in range(n):
        s = S[i]
        t = T[i]
        if t not in d:
            d[t] = s
        if d[t] != s:
            return False
        if s not in m:
            m[s] = t
        if m[s] != t:
            return False
    return True


def main():
    S = input()
    T = input()
    if check(S, T):
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

dic_s = {}
dic_t = {}

for i in range(len(S)):
    if not S[i] in dic_s.keys():
        dic_s[S[i]] = T[i]
    if not T[i] in dic_t.keys():
        dic_t[T[i]] = S[i]
    if dic_s[S[i]] != T[i] or dic_t[T[i]] != S[i]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
S=input()
T=input()
al=[chr(ord('a')+i) for i in range(26)]
sameS=[]
sameT=[]

for k in al:
    indexes=[i for i, x in enumerate(S) if x==k]
    sameS.append(indexes)

for k in al:
    indexes=[i for i, x in enumerate(T) if x==k]
    sameT.append(indexes)

if all([x in sameS for x in sameT]) and all([x in sameT for x in sameS]):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
S=input()
T=input()
al=[chr(ord('a')+i) for i in range(26)]
sameS=[]
sameT=[]
 
for k in al:
    indexes=[i for i, x in enumerate(S) if x==k]
    sameS.append(indexes)
 
for k in al:
    indexes=[i for i, x in enumerate(T) if x==k]
    sameT.append(indexes)
 
if all([x in sameS for x in sameT]) and all([x in sameT for x in sameS]):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

def f():
  dicS, dicT = {}, {}
  for i in range(len(S)):
    if dicS.get(S[i], '') == '':
      dicS[S[i]] = T[i]
    else:
      if dicS[S[i]] != T[i]:
        return 'No'
    if dicT.get(T[i], '') == '':
      dicT[T[i]] = S[i]
    else:
      if dicT[T[i]] != S[i]:
        return 'No'
  return 'Yes'
print(f())

Submission status: Accepted

Solution code:
s = input()
t = input()
f = ""
d = {}
for i in range(len(s)):
    if s[i] not in d:
        d[s[i]] = t[i]
    f += d[s[i]]
if f == t and len(d.values()) == len(set(d.values())):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

start = [-1] * 26
goal = [-1] * 26
flag = True
length = len(s)
dict = { chr(97 + i):i for i in range(26) }
for i in range(0, length):
	a = dict[s[i]]
	b = dict[t[i]]

	if start[a] != -1 or goal[b] != -1:
		if start[a] != b or goal[b] != a:
			flag = False
			break
	else:
		start[a] = b;
		goal[b] = a;
if flag:
	print("Yes")
else:
	print("No")

Submission status: Accepted

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

count_s = dict(zip([chr(i) for i in range(97, 97+26)], [0]*26))
count_t = dict(zip([chr(i) for i in range(97, 97+26)], [0]*26))
for ss, tt in zip(s, t):
    count_s[ss] += 1
    count_t[tt] += 1
v_s = sorted(count_s.values())
v_t = sorted(count_t.values())

ans = 'Yes' if v_s == v_t else 'No'
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter as C
s=list(input())
t=list(input())
print('YNeos'[C(C(s).values())!=C(C(t).values())::2])

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
n = len(s)
sl = [0] * n
tl = [0] * n
sd = {}
td = {}
for i in range(n):
    c = s[i]
    if c not in sd:
        sd[c] = i
        sl[i] = i
    else:
        sl[i] = sd[c]
for i in range(n):
    c = t[i]
    if c not in td:
        td[c] = i
        tl[i] = i
    else:
        tl[i] = td[c]
if sl == tl:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s,t = input(),input()
def g(s,t):
    for j in range(len(s)):
        if len(s) == len(t):
            S = [i for i in s if i != s[0]]
            T = [i for i in t if i != t[0]]
            s = S
            t = T
        else:
            return 'No'
    return 'Yes'
print(g(s,t))

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

s = input()
t = input()

s_dic = dict()
t_dic = dict()

flag = True
for i in range(len(s)):
    s_i = s[i]
    t_i = t[i]
    if s_i not in s_dic:
        s_dic[s_i] = t_i
    else:
        if s_dic[s_i] != t_i:
            flag = False
    if t_i not in t_dic:
        t_dic[t_i] = s_i
    else:
        if t_dic[t_i] != s_i:
            flag = False

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

Submission status: Accepted

Solution code:
s = input()
t = input()
s_list = []
t_list = []

for i in range(26):
    s_list.append(s.count(chr(97+i)))
    t_list.append(t.count(chr(97+i)))

s_list.sort()
t_list.sort()
true = 0
for i in range(26):
    if s_list[i] != t_list[i]:
        print('No')
        break
    else:
        true += 1
if true == 26:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S, T = input(), input()
cnt1, cnt2, r1, r2 =[], [], [], []
for c in S:
    if not c in r1:
        cnt1.append(S.count(c))
        r1.append(c)
for c in T:
    if not c in r2:
        cnt2.append(T.count(c))
        r2.append(c)
#cnt1.sort()
#cnt2.sort()
if cnt1 == cnt2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
S, T = input(), input()
cnt1, cnt2, r1, r2 =[], [], [], []
for c in S:
    if not c in r1:
        cnt1.append(S.count(c))
        r1.append(c)
for c in T:
    if not c in r2:
        cnt2.append(T.count(c))
        r2.append(c)
cnt1.sort()
cnt2.sort()
if cnt1 == cnt2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
dict={
  'a':0,'b':1,'c':2,'d':3,'e':4,'f':5,'g':6,'h':7,'i':8,'j':9,'k':10,'l':11,'m':12,'n':13,'o':14,'p':15,'q':16,'r':17,'s':18,'t':19,'u':20,'v':21,'w':22,'x':23,'y':24,'z':25,
}
l1=['']*26
l2=['']*26
s1=input()
s2=input()
f=0
for i in range(len(s1)):
  a=s1[i]
  b=s2[i]
  ind=dict[a]
  if l1[ind]=='':
    l1[ind]=b
  else:
    if l1[ind]!=b:
      f=1
      break
  ind=dict[b]
  if l2[ind]=='':
    l2[ind]=a
  else:
    if l2[ind]!=a:
      f=1
      break
if f==1:
  print('No')
else:
  print('Yes')

Submission status: Accepted

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

sc = ["" for i in range(0, 26)]
tc = ["" for i in range(0, 26)]
scf = False
tcf = False
for i in range(0, len(s)):
    sci = sc[ord(s[i]) - ord('a')]
    if sci != "" and t[i] != sci:
        print("No")
        scf = True
        break
    else:
        sc[ord(s[i]) - ord('a')] = t[i]

if not scf:
    for i in range(0, len(t)):
        tci = tc[ord(t[i]) - ord('a')]
        if tci != "" and s[i] != tci:
            print("No")
            tcf = True
            break
        else:
            tc[ord(t[i]) - ord('a')] = s[i]
    if not tcf:
        print("Yes")

Submission status: Accepted

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

n = len(str1)
d1 = dict()
d2 = dict()
for i in range(26):
    d1[chr(97+i)] = ''
    d2[chr(97+i)] = ''
res = "Yes"
for i in range(n):
    if d1[str1[i]] != '' and d1[str1[i]]!=str2[i]:
        res = "No"
        break
    if d2[str2[i]] != '' and d2[str2[i]]!=str1[i]:
        res = "No"
        break
    if d1[str1[i]] == '':
        d1[str1[i]] = str2[i]
    if d2[str2[i]] == '':
        d2[str2[i]] = str1[i]
print(res)

Submission status: Accepted

Solution code:
import collections as cl
s=input()
t=input()
s_count=cl.Counter(s)
t_count=cl.Counter(t)
a=sorted(s_count.values())
b=sorted(t_count.values())
if a==b:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

st = {}
tset = set()
out = 'Yes'
for _s, _t in zip(s, t):
  if _s in st:
    if st[_s] != _t:
      out = 'No'
      break
  elif _t in tset:
    out = 'No'
    break
  else:
    st[_s] = _t
    tset.add(_t)
print(out)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc110/tasks/abc110_c

S = input()
T = input()


def to_dict(s):
    dic = {}
    for c in list(s):
        if c in dic:
            dic[c] += 1
        else:
            dic[c] = 1

    return sorted(list(dic.values()))


sl = to_dict(S)
tl = to_dict(T)

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

Submission status: Accepted

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

def judge(s1, s2):
    d = {}
    for i,c in enumerate(s1):
        if c not in d:
            d[c] = [i]
        else:
            d[c].append(i)
    for v in d.values():
        a = v[0]
        for b in v:
            if s2[a]!=s2[b]:
                return 0
            a = b
    return 1

if judge(S,T)*judge(T,S) == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s=(input())
t=(input())
a=[chr(ord("a")+i)for i in range(26)]
b=[chr(ord("a")+i)for i in range(26)]
for i in range(0,len(s)):
    p=ord(s[i])-ord("a")
    q=ord(t[i])-ord("a")
    if len(a[p])==1:
        a[p]=t[i]+"1"
    else:
        if a[p]!=t[i]+"1":
            print("No")
            break
    if len(b[q])==1:
        b[q]=s[i]+"1"
    else:
        if b[q]!=s[i]+"1":
            print("No")
            break
else:
    print("Yes")

Submission status: Accepted

Solution code:
A = list(input())
B = list(input())
dicB = {}
dicA = {}
for i in range(len(A)):
    dicB.setdefault(B[i], A[i])
    dicA.setdefault(A[i], B[i])
    if dicB.get(B[i]) != A[i] or dicA.get(A[i]) != B[i]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
from collections import defaultdict
str_s = input()
str_t = input()


def check_pattern(str):
    checkdict = defaultdict(int)
    pattern = list()
    for w in str:
        if w not in checkdict:
            checkdict[w] = len(checkdict) + 1

        pattern.append(checkdict[w])
    return pattern


if check_pattern(str_s) == check_pattern(str_t):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import collections as col

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

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

cv1 = sorted(c1.values())
cv2 = sorted(c2.values())

if cv1 == cv2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

import collections
s_count = collections.Counter(s)
t_count = collections.Counter(t)

if sorted(s_count.values()) == sorted(t_count.values()):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

for i in s:
    if i not in letter_list:
        letter_list.append(i)
        id_list.append(len(set(id_list)) + 1)
    else:
        id_list.append(letter_list.index(i) + 1)
        
        
letter_list = list()
id_list2 = list()

for i in t:
    if i not in letter_list:
        letter_list.append(i)
        id_list2.append(len(set(id_list2)) + 1)
    else:
        id_list2.append(letter_list.index(i) + 1)
        
if id_list == id_list2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
S = input()
T = input()
st = {}
ts = {}
for s, t in zip(S, T):
    if s in st and st[s] != t:
        print("No")
        exit()
    if t in ts and ts[t] != s:
        print("No")
        exit()
    st[s] = t
    ts[t] = s
print("Yes")

Submission status: Accepted

Solution code:
s, t = input(), input()
f = [-1] * 27
can = True
count = 0
for i in range(len(s)):
    if f[ord(s[i])-ord("a")] == -1:
        f[ord(s[i])-ord("a")] = ord(t[i]) - ord("a")
        count += 1
    elif f[ord(s[i])-ord("a")] == ord(t[i]) - ord("a"):
        continue
    else:
        can = False
        break
if len(set(f)) != count+1:
    can = False
if can:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter as C
print(["No", "Yes"][C(C(input()).values()) == C(C(input()).values())])

Submission status: Accepted

Solution code:
s=input()
t=input()
 
listA=[s.count(chr(i)) for i in range(ord('a'),ord('z')+1)]
listB=[t.count(chr(i)) for i in range(ord('a'),ord('z')+1)]

listA.sort()
listB.sort()

print('Yes' if listA==listB else 'No')

Submission status: Accepted

Solution code:
s=input()
t=input()
#print(s,t)

listA=[s.count(chr(i)) for i in range(97,122+1)]
listB=[t.count(chr(i)) for i in range(97,122+1)]
#print(listA)
#print(listB)

listA.sort()
listB.sort()
#print(listA)
#print(listB)

print('Yes' if listA==listB else 'No')

Submission status: Accepted

Solution code:
import sys
 
def main():
  input = sys.stdin.readline
  S = str(input().strip())
  T = str(input().strip())
  
  C1, C2 = [], []
  ans = 'Yes'
  S2T = dict()
  T2S = dict()
  for c1, c2 in zip(S, T):
    if (c1 in S2T) and (c2 in T2S):
      if not((S2T[c1] == c2) and (T2S[c2] == c1)):
        ans = 'No'
        break
    elif (c1 not in S2T) and (c2 not in T2S):
      S2T[c1] = c2
      T2S[c2] = c1
    else:
      ans = 'No'
      break
  print(ans)
 
 
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  T = str(input().strip())
  
  C1, C2 = [], []
  ans = 'Yes'
  S2T = dict()
  T2S = dict()
  for c1, c2 in zip(S, T):
    if (c1 in S2T) and (c2 in T2S):
      if (S2T[c1] == c2) and (T2S[c2] == c1):
        continue
      else:
        ans = 'No'
        break
    elif (c1 in S2T):
      if S2T[c1] == c2:
        T2S[c2] = c1
        continue
      else:
        ans = 'No'
        break
    elif (c2 in T2S):
      if T2S[c2] == c1:
        S2T[c1] == c2
        continue
      else:
        ans = 'No'
        break
    else:
      S2T[c1] = c2
      T2S[c2] = c1
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
#アルファベットの1対1置換が存在すればYes
S=input()
T=input()
#dは、アルファベットの置換、置換は辞書で書く
d={}
#Sを順にみていって、d内になかったらSのi番目とdのi番目が置換関係にある
for i in range(len(S)):
    if S[i] not in d:
        d[S[i]]=T[i] 
    else:
      #1対1の置換でないと判明したらNoを出力
        if d[S[i]]!=T[i]:
            print('No')
            exit()
d={}
for i in range(len(T)):
    if T[i] not in d:
        d[T[i]]=S[i]
    else:
        if d[T[i]]!=S[i]:
            print('No')
            exit()
print('Yes')

Submission status: Accepted

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

def combocount(st):
    res = []
    count = 0
    tmp = {}
    for c in st:
        # tukatta koto ga aru
        if c in tmp:
            res.append(tmp[c])
        # hazimete
        else:
            tmp[c] = count
            res.append(count)
            count += 1
    return res


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

Submission status: Accepted

Solution code:
S = input()
T = input()
s, t = [], []
for alp in "abcdefghijklmnopqrstuvwxyz":
  s.append(S.count(alp))
  t.append(T.count(alp))
if(sorted(s) == sorted(t)):
  print("Yes")
else:
  print("No")