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 sys
s=input()
t=input()
s_dict={}
t_dict={}
for i in range(len(s)):
    if not s[i] in s_dict:
        s_dict[s[i]]=t[i]
    else:
        if s_dict[s[i]]==t[i]:
            pass
        else:
            print('No')
            sys.exit()
    if not t[i] in t_dict:
        t_dict[t[i]]=s[i]
    else:
        if t_dict[t[i]]==s[i]:
            pass
        else:
            print('No')
            sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
S=input()
T=input()
char_dict={}
target_chatrs=[]
is_valid=True
for i in range(len(S)):
    if S[i] not in char_dict:
        if T[i] in target_chatrs:
            is_valid=False
            break
        char_dict[S[i]]=T[i]
        target_chatrs.append(T[i])
    else:
        if char_dict[S[i]]!=T[i]:
            is_valid=False
            break
if is_valid:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np
from copy import deepcopy

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

line_S = deepcopy(S)
line_T = deepcopy(T)

while True:
  if len(line_S) == 0:
    ans = 'Yes'
    break
  else:
    char_S = line_S[0]
    char_T = line_T[0]
    bool_S = [(s == char_S) for s in line_S]
    bool_T = [(t == char_T) for t in line_T]
    if bool_S == bool_T:
      line_S = line_S.replace(char_S, "")
      line_T = line_T.replace(char_T, "")
    else:
      ans = 'No'
      break
   
print(ans)

Submission status: Accepted

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

char_dict = {}
target_chars = []

is_valid = True
for i in range(len(S)):
    if S[i] in char_dict:
        if char_dict[S[i]] != T[i]:
            is_valid = False
            break
    else:
        if T[i] in target_chars:
            is_valid = False
            break
        char_dict[S[i]] = T[i]
        target_chars.append(T[i])

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

Submission status: Accepted

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

def compare(a, b):
    dict = {}
    flag = 1
    for i in range(len(a)):
        if a[i] in dict:
            dict[a[i]].append(i)
        else:
            dict[a[i]] = [i]
    for list in dict.values():
        bvals = [b[i] for i in list]
        if bvals.count(bvals[0]) != len(bvals):
            flag = 0
            break
    return flag

res = compare(s, t) * compare(t, s)
if res:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
S = input()
T = input()
N = len(S)
d = {}
d1 = {}
for i in range(N):
    if S[i] in d:
        if d[S[i]] != T[i]:
            print('No')
            exit()
    elif T[i] in d1:
        if d1[T[i]] != S[i]:
            print('No')
            exit()
    else:
        d[S[i]] = T[i]
        d1[T[i]] = S[i]

print('Yes')

Submission status: Accepted

Solution code:
from collections import Counter

S = input()
T = input()

S_cnt = Counter(S).most_common()
T_cnt = Counter(T).most_common()

if len(S_cnt) != len(T_cnt):
    print('No')
else:
    for i in range(len(S_cnt)):
        if S_cnt[i][1] != T_cnt[i][1]:
            print('No')
            exit()
    print('Yes')

Submission status: Accepted

Solution code:
import sys
S = input()
T = input()
alpha = []
rule = {}
for i in range(len(S)):
	if S[i] in rule.keys():
		if rule[S[i]] != T[i]:
			print('No')
			sys.exit()
	elif T[i] in rule.values():
		print('No')
		sys.exit()
	else:
		rule[S[i]] = T[i]
print('Yes')

Submission status: Accepted

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


dict_S = {}
dict_T = {}

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

Submission status: Accepted

Solution code:
s_in=input()
t_in=input()

dicword_s={}
dicword_t={}
for s,t in zip(s_in,t_in):
    if s in dicword_s:
        if t != dicword_s[s]:
            print("No")
            exit()
    else:
        dicword_s[s] = t

    if t in dicword_t:
        if s != dicword_t[t]:
            print("No")
            exit()
    else:
        dicword_t[t] = s
print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(S: str, T: str):
    ds = {}
    dt = {}
    cs = []
    ct = []
    for s, t in zip(S, T):
        if s in ds:
            cs.append(ds[s])
        else:
            cc = len(ds) + 1
            ds[s] = cc
            cs.append(cc)
        if t in dt:
            ct.append(dt[t])
        else:
            cc = len(dt) + 1
            dt[t] = cc
            ct.append(cc)
    return YES if cs == ct else NO


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    result = solve(S, T)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def pattern(s):
  s_dict = {}
  pattern = [None for _ in range(len(s))]
  for i,c in enumerate(s):
    if not c in s_dict:
      s_dict[c] = len(s_dict)
    pattern[i] = s_dict[c]
  return pattern

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

Submission status: Accepted

Solution code:
from collections import Counter


def f(s, t):
    sc = Counter(s)
    tc = Counter(t)
    sn = [x for x in sc.values()]
    tn = [x for x in tc.values()]
    sn.sort()
    tn.sort()
    print("Yes") if sn == tn else print("No")


s = input()
t = input()
f(s, t)

Submission status: Accepted

Solution code:
from collections import Counter

s=input()
t=input()
sc=Counter(s)
tc=Counter(t)
sn=[x for x in sc.values()]
tn=[x for x in tc.values()]
sn.sort()
tn.sort()
print("Yes") if sn==tn else print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import collections


S = input()
T = input()

cnt_S = collections.Counter(S)
cnt_T = collections.Counter(T)
S_values, S_counts = zip(*cnt_S.most_common())
T_values, T_counts = zip(*cnt_T.most_common())
if S_counts == T_counts:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

while s != '':
    if [i for i, x in enumerate(s) if x == s[0]] == [i for i, x in enumerate(t) if x == t[0]]:
        s = s.replace(s[0],'')
        t = t.replace(t[0],'')
    else:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

Rs = [-1 for x in range(26)]
Rt = [-1 for x in range(26)]

l = len(S)

for i in range(l):
    s = ord(S[i])-97
    t = ord(T[i])-97
    if Rs[s] == -1:
        Rs[s] = t
    else:
        if Rs[s] != t:
            print("No")
            exit()
    
    if Rt[t] == -1:
        Rt[t] = s
    else:
        if Rt[t] != s:
            print("No")
            exit()

print("Yes")

Submission status: Accepted

Solution code:
#from collections import Counter

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

dics = {}
dicst= {}
sets = set()
sett = set()
flag = True
for i in range(len(S)):
    s = S[i]
    t = T[i]
    if s in sets and t in sett:
        if dics[s] != t or dicst[t] != s:
            flag = False
            break
    elif s in sets and not(t in sett):
        flag = False
        break
    elif t in sett and not(s in sets):
        flag = False
        break
    else:
        sets.add(s)
        sett.add(t)
        dics[s] = t
        dicst[t] = s
    
print('Yes') if flag else print('No')

Submission status: Accepted

Solution code:
#coding:utf-8
'''
S、あるいはTに含まれる文字Xを一つとってきたときに、
Xが配置されている場所群が、SとTとで同じであればYes、そうでなければNoと出力すればよい。
'''

S = input()
T = input()

S_dict = {}
for i,s in enumerate(S):
    if s not in S_dict:
        S_dict[s] = i

T_dict = {}
for i,t in enumerate(T):
    if t not in T_dict:
        T_dict[t] = i

for s, t in zip(S, T):
    if S_dict[s] == T_dict[t]:
        pass
    else:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
def gnum(str):
  return ord(str) - 97

S = input()
T = input()

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

c = 0

for i in range(len(S)):
  if R[gnum(S[i])] < 0:
    R[gnum(S[i])] = gnum(T[i])
  else:
    if R[gnum(S[i])] != gnum(T[i]):
      c = 1

  if RR[gnum(T[i])] < 0:
    RR[gnum(T[i])] = gnum(S[i])
  else:
    if RR[gnum(T[i])] != gnum(S[i]):
      c = 1

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

Submission status: Accepted

Solution code:
import string
S = input()
T = input()
L = len(S)

s_hash = {}
t_hash = {}
for i in string.ascii_lowercase:
  s_hash[i] = -1
  t_hash[i] = -1

s = []
t = []
for i in range(L):
  if s_hash[S[i]] == -1:
    s_hash[S[i]] = i
  if t_hash[T[i]] == -1:
    t_hash[T[i]] = i
  s.append(s_hash[S[i]])
  t.append(t_hash[T[i]])

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

Submission status: Accepted

Solution code:
import collections


S = input()
T = input()
cnt_S = collections.Counter(S)
cnt_T = collections.Counter(T)
S_values, S_counts = zip(*cnt_S.most_common())
T_values, T_counts = zip(*cnt_T.most_common())
if S_counts == T_counts:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# def makelist(n, m):
#     return [[0 for i in range(m)] for j in range(n)]

S = input()
T = input()

st = {}
ts = {}

yes = "Yes"
no = "No"

ans = yes
for i in range(len(S)):
    s = S[i]
    t = T[i]
    if s not in st and t not in ts:
        st[s] = t
        ts[t] = s
    elif s in st:
        if st[s] != t:
            ans = no
            break
    else:
        ans = no
        break
print(ans)

Submission status: Accepted

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

v1_to_v2 = {}
v2_to_v1 = {}

dep = ord("z") - ord("a")

def get_end(v, start, depth=0):
    result = to.get(v)
    if result == start:
        return True
    if depth > dep:
        return False
    if result is None:
        return True
    return get_end(result, start, depth + 1)


visited = [True] * n

changes = set()
for v1, v2 in zip(s, t):
    if v1_to_v2.get(v1) is not None and v1_to_v2[v1] != v2:
        print("No")
        exit()
    if v2_to_v1.get(v2) is not None and v2_to_v1[v2] != v1:
        print("No")
        exit()

    # if v2 in changes:
    #     print("No")

    v1_to_v2[v1] = v2
    v2_to_v1[v2] = v1
    # print(to)
    # print(v1, get_end(v1, v1), "v1")
    # to[v2] = v1
    # print(to)
    # print(v2, get_end(v2, v2), "v2")
print("Yes")


# s = sorted(input())
# t = sorted(input())
#
#
# def count_up(string):
#     results = []
#     prev = None
#     cnt = 0
#     for v in string:
#         if v == prev:
#             cnt += 1
#         else:
#             results.append(cnt)
#             cnt = 1
#             prev = v
#     results.append(cnt)
#     return results[1:]
#
# print(s)
# print(t)
# print("Yes" if count_up(s) == count_up(t) else "No")
#

Submission status: Accepted

Solution code:
s=input()
t=input()
def convert(S):
  lis=[]
  dic=dict()
  con=""
  for i in range(len(S)):
    if S[i] in lis:
      con+=str(dic[S[i]])
    else:
      lis.append(S[i])
      con+=str(len(lis))
      dic[S[i]]=len(lis)
  return con
print("Yes" if convert(s)==convert(t) else "No")

Submission status: Accepted

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

#print(s)
#print(t)

sset = list(set(s))
tset = list(set(t))

#print(sset)
#print(tset)

s_getindex = []
t_getindex = []

for j in range(len(sset)):
    s_getindex.append([i for i, x in enumerate(s) if x == sset[j]])

for jj in range(len(tset)):
    t_getindex.append([ii for ii, y in enumerate(t) if y == tset[jj]])

#print(s_getindex)
#print(t_getindex)

check_s = []
check_t = []
ans = 0

for k in range(len(sset)):
    if len(s_getindex[k]) != 1:
        for m in s_getindex[k]:
            check_s.append(t[m])
#        print(check_s)
#        print(len(set(check_s)))
        if len(set(check_s)) != 1:
            ans = ans + 1
#            print(s[m])
        check_s.clear()

for kk in range(len(tset)):
    if len(t_getindex[kk]) != 1:
        for mm in t_getindex[kk]:
            check_t.append(s[mm])
        if len(set(check_t)) != 1:
            ans = ans + 1
#            print(t[mm])
        check_t.clear()

#print(ans)

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

Submission status: Accepted

Solution code:
from collections import*
e=defaultdict(list)
d=defaultdict(list)
for k,v in enumerate(input()):
    e[v].append(k)
for k,v in enumerate(input()):
    d[v].append(k)
if set(map(tuple,e.values()))==set(map(tuple,d.values())):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

s_read_chars = []
t_read_chars = []

encoded_S = ""
encoded_T = ""

for s, t in zip(S, T):
    if s not in s_read_chars:
        i = len(s_read_chars)
        s_read_chars.append(s)
    else:
        i = s_read_chars.index(s)
    encoded_S += str(i)
        
    if t not in t_read_chars:
        j = len(t_read_chars)
        t_read_chars.append(t)
    else:
        j = t_read_chars.index(t)
    encoded_T += str(j)

if encoded_S == encoded_T:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:

from collections import defaultdict

def main():
    a = list(input())
    b = list(input())
    move_dic = defaultdict(str)

    flg = 1
    for i in range(len(a)):
        char_a = a[i]
        char_b = b[i]

        if char_a in move_dic:
            if move_dic[char_a] != char_b:
                flg = 0
                break
        else:
            move_dic[char_a] = char_b
    if len(list(move_dic.values())) != len(set(list(move_dic.values()))):
        flg = 0
    if flg:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(S: str, T: str):
    n = len(S)
    m_in = {}
    m_out = {}
    for i in range(n):
        if (S[i] in m_in and m_in[S[i]] != T[i]) or (T[i] in m_out and m_out[T[i]] != S[i]):
            ret = NO
            print(ret)
            return
        else:
            m_in[S[i]] = T[i]
            m_out[T[i]] = S[i]
    print(YES)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque
from fractions import gcd
#from math import factorial
from math import sqrt
from math import ceil
from itertools import permutations
from heapq import *
from collections import defaultdict
from copy import deepcopy

from bisect import bisect_left as bl

S=input()
T=input()
N=len(S)
dic1=defaultdict(int)
for i in range(N):
    s=S[i]
    t=T[i]
    if s in dic1.keys():
        if t!=dic1[s]:
            print("No")
            quit()
    else:
        dic1[s]=t
dic2=defaultdict(int)
for i in range(N):
    s=S[i]
    t=T[i]
    if t in dic2.keys():
        if s!=dic2[t]:
            print("No")
            quit()
    else:
        dic2[t]=s
print("Yes")

Submission status: Accepted

Solution code:
import sys
T=input()
S=input()
Ts=set(T)
Ss=set(S)
for v in Ts:
  ind=[i for i, x in enumerate(T) if x == v]
  for i in range(len(ind)):
    if i==0:
      continue
    if not S[ind[i-1]]==S[ind[i]]:
      print("No")
      sys.exit()
for v in Ss:
  ind=[i for i, x in enumerate(S) if x == v]
  for i in range(len(ind)):
    if i==0:
      continue
    if not T[ind[i-1]]==T[ind[i]]:
      print("No")
      sys.exit()
print("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

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

dict1 = {}
for s in S:
  if(s in dict1): dict1[s] += 1
  else: dict1[s] = 1   
dict2 = {}
for t in T:
  if(t in dict2): dict2[t] += 1
  else: dict2[t] = 1

list1,list2 = [],[]
for k, v in sorted(dict1.items(), key=lambda x: x[1]):
  list1.append(v)
for k, v in sorted(dict2.items(), key=lambda x: x[1]):
  list2.append(v)

#結局,要素の種類と個数が一致していたらOK
if(list1 == list2):
 print('Yes')
else:
 print('No')

Submission status: Accepted

Solution code:
s=input()
n=input()
d=dict()
dd=dict()
ans="Yes"
for i in range(len(s)):
  if s[i] not in d:
    d[s[i]]=n[i]
  elif d[s[i]]!=n[i]:
    ans="No"
  if n[i] not in dd:
    dd[n[i]]=s[i]
  elif dd[n[i]]!=s[i]:
    ans="No"
print(ans)

Submission status: Accepted

Solution code:
import collections


if __name__ == '__main__':
    s = input()
    t = input()

    s_freq_values = list(collections.Counter(s).values())
    s_freq_values.sort()

    t_freq_values = list(collections.Counter(t).values())
    t_freq_values.sort()

    if t_freq_values == s_freq_values:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
S = input()
T = input()
slist,tlist = {},{}
S2,T2 = [],[]
scount,tcount = 0,0

for i in range(len(S)):
  if S[i] not in slist.keys():
    slist[S[i]] = scount
    scount += 1
  S2.append(slist[S[i]]) 

  if T[i] not in tlist.keys():
    tlist[T[i]] = tcount
    tcount += 1
  T2.append(tlist[T[i]]) 
#print(S2,T2,sep="\n")
if S2 == T2:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
S = input()
T = input()
list1 = {}
list2 = {}

flag = True
for i in range(len(S)):
    if S[i] in list1.keys():
        if list1[S[i]] != T[i]:
            flag = False
    if T[i] in list2.keys():
        if list2[T[i]] != S[i]:
            flag = False
    list1[S[i]] = T[i]
    list2[T[i]] = S[i]

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

Submission status: Accepted

Solution code:
import collections as col
s = list(input())
t = list(input())
s_1 = col.Counter(s)
t_1 = col.Counter(t)
s_2 = sorted(s_1.values())
t_2 = sorted(t_1.values())
if s_2 == t_2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

d_s2t = dict()
d_t2s = dict()

flg = True
for ss, tt in zip(s, t):
    if d_s2t.get(ss) is None:
        d_s2t[ss] = tt
    else:
        if not d_s2t[ss] == tt:
            flg = False
            break

    if d_t2s.get(tt) is None:
        d_t2s[tt] = ss
    else:
        if not d_t2s[tt] == ss:
            flg = False
            break

if flg:
    if len(set(d_s2t.keys())) != len(set(d_s2t.values())):
        flg = False
    if len(set(d_t2s.keys())) != len(set(d_t2s.values())):
        flg = False

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

Submission status: Accepted

Solution code:
from string import ascii_lowercase

s = input()
t = input()

d_s2t = dict()
d_t2s = dict()

flg = True
for ss, tt in zip(s, t):
    if d_s2t.get(ss) is None:
        d_s2t[ss] = tt
    else:
        if not d_s2t[ss] == tt:
            flg = False
            break

    if d_t2s.get(tt) is None:
        d_t2s[tt] = ss
    else:
        if not d_t2s[tt] == ss:
            flg = False
            break

if flg:
    if len(set(d_s2t.keys())) != len(set(d_s2t.values())):
        flg = False
    if len(set(d_t2s.keys())) != len(set(d_t2s.values())):
        flg = False

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

Submission status: Accepted

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

dic1 = {}
dic2 = {}
f = True
for i,j in zip(s,t):
    if i in dic1:
        if dic1[i] != j:
            f = False
    else:
        dic1[i] = j
    if j in dic2:
        if dic2[j] != i:
            f = False
    else:
        dic2[j] = i
if f:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def calc(S, T):
    # 差を計算する
    ans = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            ans += 1
    return ans


def solve():
    s = input()
    S = [moji for moji in s]
    T = input()

    # 文字の置き換えをして、差が減ってなかったら無理？
    
    diff = calc(S, T)
    if diff == 0:
        print("Yes")
        return

    pre_diff = diff

    while True:
        # c1, c2を決める
        for i in range(len(S)):
            if S[i] != T[i]:
                c1 = S[i]
                c2 = T[i]
                break
        
        # 文字を置き換える
        for i in range(len(S)):
            if S[i] == c1:
                S[i] = c2
            elif S[i] == c2:
                S[i] = c1
        
        # 差を計算する
        diff = calc(S, T)
        if diff == 0:
            print("Yes")
            return
        elif diff < pre_diff:
            pre_diff = diff
            continue
        else:
            print("No")
            return


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

def calc(S, T):
    # 差を計算する
    ans = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            ans += 1
    return ans


def solve():
    s = input()
    S = [moji for moji in s]
    T = input()

    # 文字の置き換えをして、差が減ってなかったら無理？
    
    diff = calc(S, T)
    if diff == 0:
        print("Yes")
        return
    pre_diff = diff

    while True:
        # c1, c2を決める
        for i in range(len(S)):
            if S[i] != T[i]:
                c1 = S[i]
                c2 = T[i]
                break
        
        # 文字を置き換える
        for i in range(len(S)):
            if S[i] == c1:
                S[i] = c2
            elif S[i] == c2:
                S[i] = c1
        
        # 差を計算する
        diff = calc(S, T)
        if diff == 0:
            break
        elif diff < pre_diff:
            pre_diff = diff
            continue
        else:
            print("No")
            return
    print("Yes")





if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
s = input()
t = input()
dic1 = {}
dic2 = {}
f = True
for i, j in zip(s, t):
    if i in dic1:
        if dic1[i] != j:
            f = False
            break
    dic1[i] = j
    if j in dic2:
        if dic2[j] != i:
            f = False
            break
    dic2[j] = i
if f:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import collections

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str, T: str):
    wcS = collections.defaultdict(int)
    wcT = collections.defaultdict(int)
    for c in S:
        wcS[c] += 1
    for c in T:
        wcT[c] += 1
    cS = collections.defaultdict(int)
    cT = collections.defaultdict(int)
    for key in wcS:
        cS[wcS[key]] += 1
    for key in wcT:
        cT[wcT[key]] += 1
    representable = True
    if len(cT.keys()) > len(cS.keys()):
        temp = cT
        cT = cS
        cS = temp
    for key in cS:
        if cT[key] != cS[key]:
            representable = False
    print(YES if representable else NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
T = input()
check = {'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'}
alll = ['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']
alfa = {'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'}
count_s = set()
count_t = set()
nums = 0
numt = 0
for s in range(len(S)):
    if count_s == alfa:
        break
    if S[s] in check:
        continue
    count_s.add(S[s])
    S = S.replace(S[s],str(alll[nums]))
    nums += 1
for t in range(len(T)):
    if count_t == alfa:
        break
    if T[t] in check:
        continue
    count_t.add(T[t])
    T = T.replace(T[t],str(alll[numt]))
    numt += 1
if S == T:
    print('Yes')
else:print('No')

Submission status: Accepted

Solution code:
S = input()
T = input()
dic1 = {}
dic2 = {}
flag = True
for i , j in zip(S, T):
    if i in dic1:
        if dic1[i] != j:
            flag = False
            break
    dic1[i] = j
    if j in dic2:
        if dic2[j] != i:
            flag = False
            break
    dic2[j] = i
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

def replacer():
	m = {}
	i = ord("A")

	def replace(c):
		nonlocal i
		if c not in m:
			m[c] = chr(i)
			i += 1
		return m[c]

	return replace

rs="".join(map(replacer(), S))
rt="".join(map(replacer(), T))

print("Yes" if rs == rt else "No")

Submission status: Accepted

Solution code:
s = input()
t = input()
a = "abcdefghijklmnopqrstuvwxyz"

flag = 0
i = 0 
while i < len(s):
	if s[i] != t[i]:
		if t[i] in a:
			c = s[i]
			s = s.replace(c, "1")
			s = s.replace(t[i], c)
			s = s.replace("1", t[i])
			a = a.replace(t[i], "1")
		else:
			break
	i += 1
if s == t:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
S = [i for i in input()]
T = [i for i in input()]

judge_s, judge_t = {}, {}

idx = 0
ct = 0
for i in S:
    if judge_s.get(i):
        S[idx] = judge_s[i]
    else:
        S[idx] = ct
        judge_s[i] = ct
        ct += 1
    idx += 1

idx = 0
ct = 0
for i in T:
    if judge_t.get(i):
        T[idx] = judge_t[i]
    else:
        T[idx] = ct
        judge_t[i] = ct
        ct += 1
    idx += 1

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

Submission status: Accepted

Solution code:
S = input()
T = input()
F = 1
DD = [0 for i in range(1001)]
NUM = [0 for i in range(1001)]
grid = [i for i in range(ord('a'),ord('z')+1)]
for i in range(len(S)):
    if (not DD[ord(S[i])] == ord(T[i])) and (not DD[ord(S[i])] == 0):
        F = 0
    if DD[ord(S[i])] == 0:
        NUM[ord(T[i])] = NUM[ord(T[i])] + 1
    DD[ord(S[i])] = ord(T[i])
for i in NUM:
    if i >= 2:
        F = 0
print("Yes" if F == 1 else "No")

Submission status: Accepted

Solution code:
S = list(str(input()))
T = list(str(input()))
moji = "abcdefghijklmnopqrstuvwxyz"
tmp_1 = []
tmp_2 = []
for i in range(26):
  count = S.count(moji[i])
  tmp_1.append(count)
for i in range(26):
  count = T.count(moji[i])
  tmp_2.append(count)
tmp_1.sort()
tmp_2.sort()
if tmp_1 == tmp_2:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

ds = dict()
dt = dict()
for i in range(len(S)):
    s, t = S[i], T[i]
    if s in ds:
        if ds[s] != t:
            print('No')
            exit()
    else:
        ds[s] = t

    if t in dt:
        if dt[t] != s:
            print('No')
            exit()
    else:
        dt[t] = s

print('Yes')

Submission status: Accepted

Solution code:
s = input()
t = input()
 
s_c = []
t_c = []
for c in 'abcdefghijklmnopqrstuvwxyz':
    s_c.append(s.count(c))
    t_c.append(t.count(c))
s_c.sort()
t_c.sort()
if s_c == t_c:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
prj = {}
prj_inv = {}
s = input()
t = input()
for i, j in zip(s, t):
    if i not in prj and j not in prj_inv:
        prj[i] = j
        prj_inv[j] = i
    elif i in prj and j in prj_inv:
        if prj[i] == j:
            continue
        else:
            print('No')
            break
    else:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
def check(s, t):
    from collections import Counter
    sc = Counter(s)
    tc = Counter(t)
    return sorted(sc.values()) == sorted(tc.values())

print(['No','Yes'][check(input(),input())])

Submission status: Accepted

Solution code:
s=input()
t=input()
def C(a, b):
    d={}
    for i in range(len(a)):
        if a[i] in d:
            if d[a[i]]!=b[i]:
                return False
        else:
            d[a[i]]=b[i]
    return True
if C(s, t)and C(t, s):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s=input()
t=input()
dic1={}
for i in range(len(s)):
    if s[i] in dic1:
        if dic1[s[i]]!=t[i]:
            print("No")
            exit()
    else:
        dic1[s[i]]=t[i]
dic2={}
for k in range(len(t)):
    if t[k] in dic2:
        if dic2[t[k]]!=s[k]:
            print("No")
            exit()
    else:
        dic2[t[k]]=s[k]
print("Yes")

Submission status: Accepted

Solution code:
import collections

S = input()
T = input()

sc = sorted(list(collections.Counter(S).values()))
tc = sorted(list(collections.Counter(T).values()))

if sc == tc:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import defaultdict
#from math import factorial
from math import sqrt

S=input()
T=input()
ds=defaultdict(str)
dt=defaultdict(str)
for s,t in zip(S,T):
    if not(s in ds.keys()):
        ds[s]=t
        continue
    elif ds[s]==t:
        continue
    else:
        print("No")
        quit()
for s,t in zip(S,T):
    if not(t in dt.keys()):
        dt[t]=s
        continue
    elif dt[t]==s:
        continue
    else:
        print("No")
        quit()
print("Yes")

Submission status: Accepted

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

S_charmap={ chr(i):-1 for i in range (97,97+26)}
T_charmap={ chr(i):-1 for i in range (97,97+26)}
S_kinds=0
T_kinds=0

ans='Yes'
for i in range(N):
	if S_charmap[S[i]] == -1:
		S_kinds += 1
		S_charmap[S[i]] = S_kinds
	if T_charmap[T[i]] == -1:
		T_kinds += 1
		T_charmap[T[i]] = T_kinds
	if S_charmap[S[i]] == T_charmap[T[i]]:
		continue
	else:
		ans='No'
		break
print(ans)

Submission status: Accepted

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

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


print("Yes")