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:
def get_alphabet_num(s):
    return ord(s) - ord('a')


R = [-1] * 26
R_ = [-1] * 26
for s, t in zip(input(), input()):
    si = get_alphabet_num(s)
    ti = get_alphabet_num(t)
    if R[si] >= 0:
        # R[Si] >= 0 ならば R[Si] が Ti に等しいことを検査する
        if R[si] == ti:
            pass
        else:
            print('No')
            exit()
    if R_[ti] >= 0:
        # R_[Ti] >= 0 ならば R_[Ti] が Si に等しいことを検査する
        if R_[ti] == si:
            pass
        else:
            print('No')
            exit()
    # R[Si] < 0 ならば R[Si] := Ti とする
    R[si] = ti
    # R_[Ti] < 0 ならば R_[Ti] := Si とする
    R_[ti] = si
print('Yes')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
import re

s_in = lambda: stdin.readline()[:-1] # s = s_in()
d_in = lambda: int(stdin.readline()) # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split())) # List = ds_in()

S = s_in()
T = s_in()
N = len(S)

rec = []
idxes = [i for i in range(26)]

def alpnum(s):
    return ord(s) - ord('a')

for i in range(N):
    si = alpnum(S[i])
    ti = alpnum(T[i])
    if (idxes[si] != ti):
        if (idxes[si] in rec) or (ti in rec):
            print('No')
            exit()
        idx = idxes.index(ti)
        idxes[si], idxes[idx] = idxes[idx], idxes[si]
    rec.append(ti)
print('Yes')

Submission status: Accepted

Solution code:
from collections import defaultdict
start = defaultdict(lambda: -1)
goal = defaultdict(lambda: -1)
for s, t in zip(input(), input()):
    if start[s] != -1 or goal[t] != -1:
        if start[s] != t or goal[t] != s:
            print('No')
            exit()
    start[s], goal[t] = t, s
print('Yes')

Submission status: Accepted

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

s_c_list = []
t_c_list = []

new_S = ""
new_T = ""

for i in range(len(S)):
    if not S[i] in s_c_list:
        new_S+=str(len(s_c_list))
        s_c_list.append(S[i])
    else:
        new_S+=str(s_c_list.index(S[i]))
    if not T[i] in t_c_list:
        new_T+=str(len(t_c_list))
        t_c_list.append(T[i])
    else:
        new_T+=str(t_c_list.index(T[i]))

if new_S==new_T:
    print "Yes"
else:
    print "No"

Submission status: Accepted

Solution code:
import sys

S = input()
T = input()

r_dic = {}
s_dic = {}
for i in range(len(S)):
    s = S[i]
    t = T[i]
    # print(s, t)
    # print(r_dic, s in r_dic)

    if(t in r_dic and r_dic[t] != s):
        print("No")
        sys.exit()
    else:
        r_dic[t] = s

    if(s in s_dic and s_dic[s] != t):
        print("No")
        sys.exit()
    else:
        s_dic[s] = t

print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/env python
S = input()
T = input()
map_table = {}
imap_table = {}
fail = False
for i, c in enumerate(S):
    if S[i] not in map_table and T[i] not in imap_table:
        map_table[S[i]] = T[i]
        imap_table[T[i]] = S[i]
    if S[i] not in map_table or map_table[S[i]] != T[i]:
        fail = True
        break
    if T[i] not in imap_table or imap_table[T[i]] != S[i]:
        fail = True
        break
print('No' if fail else 'Yes')

Submission status: Accepted

Solution code:
import collections

S = input()
T = input()

S_count = [v for v in collections.Counter(S).values()]
S_count.sort()
T_count = [v for v in collections.Counter(T).values()]
T_count.sort()

if S_count == T_count:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter

S = Counter(list(input()))
T = Counter(list(input()))
s,t = list(S.values()), list(T.values())
print(["No", "Yes"][sorted(s) == sorted(t)])

Submission status: Accepted

Solution code:
import sys

s = input()
t = input()

#print(s)
#print(t)

n = len(s)

dic = {}
dic2 = {}


for i in range(n):
    if s[i] in dic:
        if dic[s[i]] != t[i]:
            print("No")
            sys.exit()
            
    else:
        dic[s[i]] = t[i]
            
            
    if t[i] in dic2:
        if dic2[t[i]] != s[i]:
            print("No")
            sys.exit()
            
    else:
        dic2[t[i]] = s[i]
        
print("Yes")

Submission status: Accepted

Solution code:
def run(s, t):
    sc = {}
    tc = {}
    for i in 'abcdefghijklmnopqrstuvwxyz':
        sc[i] = 0
        tc[i] = 0
    counter = 1
    for ss in s:
        if sc[ss] == 0:
            sc[ss] = counter
            counter += 1
    counter = 1
    for tt in t:
        if tc[tt] == 0:
            tc[tt] = counter
            counter += 1
    slist = [sc[ss] for ss in s]
    tlist = [tc[tt] for tt in t]
    if slist == tlist:
        return 'Yes'
    else:
        return 'No'
    '''
    ss = sorted(list(collections.Counter(s).values()))
    tt = sorted(list(collections.Counter(t).values()))
    if ss == tt:
        return 'Yes'
    else:
        return 'No'
    '''


def main():
    s = input()
    t = input()
    print(run(s, t))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

S = Counter(list(input()))
T = Counter(list(input()))
s,t = list(S.values()),list(T.values())
print(["No", "Yes"][Counter(s) == Counter(t)])

Submission status: Accepted

Solution code:
S = input()
T = input()
A = [-1]*26
B = [-1]*26
L = len(S)
ans = 'Yes'
for i in range(L):
    ords = ord(S[i])-97
    ordt = ord(T[i])-97
    if A[ords] == -1 and B[ordt] == -1:
        A[ords] = ordt
        B[ordt] = ords
    elif A[ords] == ordt and B[ordt] == ords:
        continue
    else:
        ans = 'No'
print(ans)

Submission status: Accepted

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

d_s2t = dict()
d_t2s = dict()

flg = True
for s, t in zip(S, T):
    if d_s2t.get(s, t) == t:
        d_s2t[s] = t
    else:
        flg = False
        break

    if d_t2s.get(t, s) == s:
        d_t2s[t] = s
    else:
        flg = False
        break

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

Submission status: Accepted

Solution code:
from collections import Counter as C

def cnt(x):
    return sorted(C(x).values())

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

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

Submission status: Accepted

Solution code:
ss = input().strip()
ts = input().strip()

mapping = {}
for s, t in zip(ss, ts):
  if mapping.get(s, t) != t:
    print("No")
    quit(0)
  mapping[s] = t
if len(mapping.values()) == len(set(mapping.values())):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
import collections

def main(S, T):
    print(S, file=sys.stderr)
    print(T, file=sys.stderr)

    m = dict()
    for s, t in zip(S, T):
        if s in m and m[s] != t:
            return "No"
        m[s] = t
    print("  ".join(m), file=sys.stderr)
    print("  ".join(m.values()), file=sys.stderr)
    c = set()
    for t in m.values():
        if t in c:
            return "No"
        c.add(t)
    return "Yes" 

assert main("chokudai", "redcoder") == "No"
assert main("azzel", "apple") == "Yes"
assert main("abcdefghijklmnopqrstuvwxyz", "ibyhqfrekavclxjstdwgpzmonu") == "Yes"
S = input()
T = input()
print(main(S, T))

Submission status: Accepted

Solution code:
import collections


def run(s, t):
    ss = sorted(list(collections.Counter(s).values()))
    tt = sorted(list(collections.Counter(t).values()))
    if ss == tt:
        return 'Yes'
    else:
        return 'No'


def main():
    s = input()
    t = input()
    print(run(s, t))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input();t=input()
u=[];c=0
for i in range(len(s)):
  v=[s[i],t[i]]
  if v not in u:
    u.append(v)
for k in range(len(u)):
  for m in range(len(u)):
    if u[k][0]==u[m][0]:
      if u[k][1]!=u[m][1]:c+=1
for p in range(len(u)):
  for q in range(len(u)):
    if u[p][1]==u[q][1]:
      if u[p][0]!=u[q][0]:c+=1
if c==0:print('Yes')
else:print('No')

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter

S = input()
T = input()

d_s = defaultdict(int)
d_t = defaultdict(int)

no_flag = False
for s, t in zip(list(S), list(T)):
    d_s[s] += 1
    d_t[t] += 1

if sorted(d_s.values()) == sorted(d_t.values()):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a=list(input())
b=list(input())
from collections import Counter
def f(s):
    return sorted(Counter(s).values())
if f(a)==f(b):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

sc = [0] * 26
tc = [0] * 26

for i in range(len(s)):
    sc[ord(s[i]) - ord("a")] += 1
    tc[ord(t[i]) - ord("a")] += 1
for snum, tnum in zip(sorted(sc), sorted(tc)):
    if snum != tnum:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
s = input()
t = input()


ok=1
sset=[[] for i in range(26)]
for i in range(len(s)):
    n=ord(s[i])-ord("a")
    sset[n].append(i)

tset=[[] for i in range(26)]
for i in range(len(t)):
    n=ord(t[i])-ord("a")
    tset[n].append(i)

for i in sset:
    if i not in tset:
        ok=0
#print(sset)
#print(tset)
if ok==1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

n = len(S)
c1s = {}
c2s = {}
ans = True
for i in range(n):
    if not ans:
        break

    if S[i] in c1s:
        if c1s[S[i]] != T[i]:
            ans = False
            break
    else:
        c1s[S[i]] = T[i]
    if T[i] in c2s:
        if c2s[T[i]] != S[i]:
            ans = False
            break
    else:
        c2s[T[i]] = S[i]


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

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
t = input()
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        if t[i] != t[i+1]:
            print("No")
            exit()
s_count = Counter(list(s)).most_common()
t_count = Counter(list(t)).most_common()
for i in range(len(s_count)):
    if s_count[i][1] != t_count[i][1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

if s==t:
    print("Yes")
    sys.exit()

alpha = [chr(i) for i in range(97, 97+26)]
checkalpha = []
checks = [0 for i in range(26)]
checkt = [0 for i in range(26)]
for i,a in enumerate(alpha):
    checks[i] = len([i for i, x in enumerate(s) if x == a])
    checkt[i] = len([i for i, x in enumerate(t) if x == a])
checks.sort()
checkt.sort()
if checks == checkt:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def main():
    data0 = input()
    data1 = input()

    flag = True
    data_tmp = data0
    count = 0
    len_data = len(data0)
    while True:
        if data0 == "":
            break

        data0 = data0.replace(data0[0], "")
        data1 = data1.replace(data1[0], "")

        if len(data0) != len(data1):
            print('No')
            exit()

    print('Yes')

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
s=input()
t=input()
u=[]
c=0
for i in range(len(s)):
  v=[s[i],t[i]]
  if v not in u:
    u.append(v)
u.sort()
for k in range(len(u)):
  for m in range(len(u)):
    if u[k][0]==u[m][0]:
      if u[k][1]!=u[m][1]:c+=1
for p in range(len(u)):
  for q in range(len(u)):
    if u[p][1]==u[q][1]:
      if u[p][0]!=u[q][0]:c+=1
if c==0:print('Yes')
else:print('No')

Submission status: Accepted

Solution code:
a = input()
b = input()
list1 = [["a", 0 ],["b", 0 ],["c", 0 ],["d", 0 ],["e", 0 ],["f", 0 ],["g", 0 ],["h", 0 ],["i", 0 ],["j", 0 ],
["k", 0 ],["l", 0 ],["m", 0 ],["n", 0 ],["o", 0 ],["p", 0 ],["q", 0 ],["r", 0 ],["s", 0 ],["t", 0 ],
["u", 0 ],["v", 0 ],["w", 0 ],["x", 0 ],["y", 0 ],["z", 0 ]]
list2 = [["a", 0 ],["b", 0 ],["c", 0 ],["d", 0 ],["e", 0 ],["f", 0 ],["g", 0 ],["h", 0 ],["i", 0 ],["j", 0 ],
["k", 0 ],["l", 0 ],["m", 0 ],["n", 0 ],["o", 0 ],["p", 0 ],["q", 0 ],["r", 0 ],["s", 0 ],["t", 0 ],
["u", 0 ],["v", 0 ],["w", 0 ],["x", 0 ],["y", 0 ],["z", 0 ]]
for i in range(len(a)):
    for j in range(26):
        if a[i] == list1[j][0]:
            list1[j][1] += 1
            break
for i in range(len(b)):
    for j in range(26):
        if b[i] == list2[j][0]:
            list2[j][1] += 1
            break
list3 = [list1[i][1] for i in range(26)]
list3.sort()
list4 = [list2[i][1] for i in range(26)]
list4.sort()
flag = True
for i in range(26):
    if int(list3[i]) != int(list4[i]):
        flag = False
if flag:print("Yes")
else:print("No")

Submission status: Accepted

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

dic = {}
dic2 = {}

# for i in range(len(s)):
#     if s[i] in dic:
#         if dic[s[i]] != t[i]:
#             print("No")
#             sys.exit()
#     else:
#         dic[s[i]] = t[i]

# print("Yes")


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

# print("Yes")

for i in range(len(s)):
    if s[i] in dic:
        if dic[s[i]] != t[i]:
            print("No")
            sys.exit()
    else:
        dic[s[i]] = t[i]

    if t[i] in dic2:
        if dic2[t[i]] != s[i]:
            print("No")
            sys.exit()
    else:
        dic2[t[i]] = s[i]

print("Yes")

Submission status: Accepted

Solution code:
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F551C':
    sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    S = read_str()
    T = read_str()
    n = len(S)
    res = 'Yes'
    A = [0] * n
    B = [0] * n
    vu = {}
    for i in range(n):
        if S[i] not in vu:
            vu[S[i]] = i
        A[i] = vu[S[i]]

    vu = {}
    for i in range(n):
        if T[i] not in vu:
            vu[T[i]] = i
        B[i] = vu[T[i]]

    if A != B:
        res = 'No'

    # for i in range(n):
    #     for j in range(n):
    #         if S[i] != S[j] and T[i] == T[j]:
    #             res = 'No'
    #         if S[i] == S[j] and T[i] != T[j]:
    #             res = 'No'
    print(res)


main()

Submission status: Accepted

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

CS = {}
for s in S:
	if s not in CS:
		CS[s] = 1
	else:
		CS[s] += 1
TS = {}
for t in T:
	if t not in TS:
		TS[t] = 1
	else:
		TS[t] += 1

if False in [CS[S[i]] == TS[T[i]] for i in range(len(T))]:
	print 'No'
else:
	print 'Yes'

Submission status: Accepted

Solution code:


st1 = input()
st2 = input()
key1 = list(st1)
key2 = list(st2)

def az_count(s):
	ss = []
	ss.append(s.count('a'))
	ss.append(s.count('b'))
	ss.append(s.count('c'))
	ss.append(s.count('d'))
	ss.append(s.count('e'))
	ss.append(s.count('f'))
	ss.append(s.count('g'))
	ss.append(s.count('h'))
	ss.append(s.count('i'))
	ss.append(s.count('j'))
	ss.append(s.count('k'))
	ss.append(s.count('l'))
	ss.append(s.count('n'))
	ss.append(s.count('m'))
	ss.append(s.count('o'))
	ss.append(s.count('p'))
	ss.append(s.count('q'))
	ss.append(s.count('r'))
	ss.append(s.count('s'))
	ss.append(s.count('t'))
	ss.append(s.count('u'))
	ss.append(s.count('v'))
	ss.append(s.count('w'))
	ss.append(s.count('x'))
	ss.append(s.count('y'))
	ss.append(s.count('z'))
	return ss

t = az_count(key1)
t1 = az_count(key2)

t.sort()
t1.sort()
if t == t1:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
sS = input().rstrip()
sT = input().rstrip()




def fConv2B(sA):
    iL = len(sA)
    dA = {}
    for s in "abcdefghijklmnopqrstuvwxyz":
        dA[s] = 0
    iCounter = 1
    for i in range(iL):
        s = sA[i]
        if s in dA:
            if dA[sA[i]] == 0:
                dA[sA[i]] = iCounter
                iCounter += 1
        if  iCounter  == 27 :
            break

    aR = [0]*iL
    for i in range(iL):
        aR[i] = dA[sA[i]]
#   print(aR)
    return aR



if fConv2B(sS) == fConv2B(sT) :
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
ls = [[] for i in range(0,26)]
lt = [[] for i in range(0,26)]
alfa = "abcdefghijklmnopqrstuvwxyz"
for i in range(0,len(s)):
    ls[alfa.index(s[i])].append(i)
    lt[alfa.index(t[i])].append(i)
ans = "Yes"
for i in range(0,26):
    if len(ls[i]) == 0:
        continue
    ok = "false"
    for j in range(0,26):
        if len(lt[j]) == 0:
            continue
        if ls[i] == lt[j]:
            ok = "true"
            lt[j] = []
    if ok == "true":
        continue
    else:
        ans = "No"
print(ans)

Submission status: Accepted

Solution code:
def translate(x,y):
    if x == y[0]:
      return y[1]
    if x == y[1]:
      return y[0]
    return x

s1 = list(input())
s2 = list(input())
list = s1

count = 0
for i in range(len(list)):
    if s1[i] != s2[i]:
      x = s1[i]
      y = s2[i]
      for j in range(len(s1)):
        if s1[j] == x:
          s1[j]=y
        elif s1[j] == y:
          s1[j]=x
      #s1 = s1.translate(str.maketrans( s1[i]+s2[i], s2[i]+s1[i]) )
      #s1.replace( s1[i], "X").replace( s2[i], x).replace( 'X' , y)
      #s1 = list(map(translate, s1))
      
      count = count+1
    if count > 27:
      break

if s1==s2:
  print ("Yes")
else:
  print ("No")

Submission status: Accepted

Solution code:
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F551C':
    sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    S = read_str()
    T = read_str()
    n = len(S)
    res = 'Yes'
    A = [0] * n
    B = [0] * n
    vu = {}
    for i in range(n):
        if S[i] in vu:
            A[i] = vu[S[i]]
        else:
            vu[S[i]] = i
            A[i] = vu[S[i]]

    vu = {}
    for i in range(n):
        if T[i] in vu:
            B[i] = vu[T[i]]
        else:
            vu[T[i]] = i
            B[i] = vu[T[i]]

    if A != B:
        res = 'No'

    # for i in range(n):
    #     for j in range(n):
    #         if S[i] != S[j] and T[i] == T[j]:
    #             res = 'No'
    #         if S[i] == S[j] and T[i] != T[j]:
    #             res = 'No'
    print(res)


main()

Submission status: Accepted

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

n = len(s)

for i in range(n) :

   snow = sls[i]
   tnow = tls[i]

   if snow == tnow :
      pass

   else:
      if tnow in sls[0:i]  :
         print('No')
         break

      else :
         for j in range(n) :
            if sls[j] == snow :
               sls[j] = tnow
            elif sls[j] == tnow :
               sls[j] = snow

else :
   if sls == tls :
      print('Yes')
   else :
      print('No')

Submission status: Accepted

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

for ch in list("abcdefghijklmnopqrstuvwxyx"):
    tmp_s, tmp_t = "", ""
    for s, t in zip(S, T):
        if s == ch or t == ch:
            if tmp_s == "" and tmp_t == "":
                tmp_s, tmp_t = s, t
        
        if s == tmp_s: 
            if t != tmp_t:  
                print("No")
                sys.exit()
        if t == tmp_t: 
            if s != tmp_s:  
                print("No")
                sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
s = input()
t = input()
l = [""]*26
m = list("abcdefghijklmnopqrstuvwxyz")

ans = ("Yes")
for i in range(len(s)):
    idx = m.index(s[i])
    if l[idx] == "":
        l[idx] = t[i]
    else:
        if l[idx] != t[i]:
            ans = "No"
            

        
n = []
for i in l:
    if i != "":
        if i in n:
            ans = "No"
        else:
            n.append(i)
        
        
print(ans)

Submission status: Accepted

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

checkDict={}
checkDict2={}
flg="Yes"

for i in range(len(s)):

  if(not(s[i] in checkDict.keys())):
    checkDict[s[i]]=t[i]
  else:
    if(checkDict[s[i]]!=t[i]):
      flg="No"

  if(not(t[i] in checkDict2.keys())):
    checkDict2[t[i]]=s[i]
  else:
    if(checkDict2[t[i]]!=s[i]):
      flg="No"
    
  
print(flg)

Submission status: Accepted

Solution code:
# coding:utf-8

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

# 英小文字のペアについて相互変換するので、同じ文字について２種類の変換はできない
# よって、異なる位置に同一種類の英小文字がでてきて、対応する文字列の文字がそれぞれ違うとき変換できない
# a~zの英小文字について、変換が必要かのフラグをつくる(0:変換なし, 1以上:返還あり)
#convList = [[0 for i in range(26)] for j in range(26)]
convList = [0] * 26

ans = 'Yes'


# 文字列SとTの同一位置で異なる文字をとりだし、異なる文字だったら変換が必要と判定
# 同一の変換組み合わせがもう一度でてきたら、循環していまい、一致させられない
for i in range(len(S)):
    charNo = ord(S[i]) - 97
    matchNo = ord(T[i]) - 97
    if S[i] != T[i]:
        for j in range(len(S)):
            if ord(S[j]) - 97 == charNo:
                # すでに一致している文字であった場合は循環してしまうため、一致できなくなる
                if S[j] == T[j]:
                    ans = 'No'
                    break
                S[j] = chr((matchNo + 97))

            elif ord(S[j]) - 97 == matchNo:
                # すでに一致している文字であった場合は循環してしまうため、一致できなくなる
                if S[j] == T[j]:
                    ans = 'No'
                    break

                S[j] = chr((charNo + 97))


        #print(S)
        #print(T)

        # すでに同じ変換をしていた場合、循環してしまい、一致できない
        # if convList[charNo] == matchNo or convList[matchNo] == charNo:
        #     #print("No: %d, S: %s, T %s" % (i, S[i], T[i]))
        #     ans = 'No'
        #     break


        convList[charNo] = matchNo
        convList[matchNo] = charNo

print(ans)

Submission status: Accepted

Solution code:
def main():
    """
    英小文字のみからなる文字列 S, T
    文字列 Sに対して、次の操作を何度でも行うことができます。

    操作
        2つの異なる英小文字 c1, c2を選び、
        Sに含まれる全ての 
        c1 を c2に、
        c2 を c1に、置き換える

    0回以上操作を行って、S を Tに一致させられるか判定

    1 <= |S| = |T| <= 2 * 10^5
    """
    S = input()
    T = input()

    ans = f(S, T)
    print(ans)


if False:
    import pytest

    @pytest.mark.randomize(S=str, T=str,
                           min_length=10, max_length=10,
                           str_attrs=("ascii_lowercase",))
    def test_f(S, T):
        assert f(S, T)


def f(S, T):
    """
    26文字存在しないとき
    S: abc
    T: def
        a -> d にしたい
        dbc
        dはSに存在しないので好きに変えられる, でよいか

    S: abc
    T: ddf
        a -> d: dbc
        b -> d: dが存在する
        bを存在しないものに変える: dzc, 状況は変わらない
        a,b入れ替えても意味がない
        a->x, b->x and x->b: bxc, 状況は変わらない

        割当がかぶっていると無理っぽい

    仮に3文字しか種類がない
    S: abc
    T: cab
        c->a, a->c: cba
        b->a, a->b: cab
    """
    import string
    ds = {c: set() for c in string.ascii_lowercase}
    dt = {c: set() for c in string.ascii_lowercase}
    for c1, c2 in zip(S, T):
        ds[c2].add(c1)
        dt[c1].add(c2)

    for c in string.ascii_lowercase:
        if len(ds[c]) >= 2 or len(dt[c]) >= 2:
            return "No"

    return "Yes"


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input();S=list(s)
t=input();T=list(t)
l=[chr(ord('a')+j) for j in range(26)]
u=[]
c=0
for i in range(len(s)):
  v=[s[i],t[i]]
  if v not in u:
    u.append(v)
u.sort()
for k in range(len(u)):
  for m in range(len(u)):
    if u[k][0]==u[m][0]:
      if u[k][1]!=u[m][1]:c+=1
for p in range(len(u)):
  for q in range(len(u)):
    if u[p][1]==u[q][1]:
      if u[p][0]!=u[q][0]:c+=1
if c==0:print('Yes')
else:print('No')

Submission status: Accepted

Solution code:
a = input()
b = input()

c = [0]*26
cc = [0]*26

for i in a:
    c[int(ord(i)-ord('a'))] += 1
    
for i in b:
    cc[int(ord(i)-ord('a'))] += 1
    
    
for i, j in zip(sorted(c), sorted(cc)):
    if i != j:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

s_dict = {}
t_dict = {}
s_drdp = sorted(set(s), key=s.index)
t_drdp = sorted(set(t), key=t.index)
for i, ss in enumerate(s_drdp):
    s_dict[ss] = i
for i, tt in enumerate(t_drdp):
    t_dict[tt] = i

import numpy as np

def s2vec(d, d_dict):
    return d_dict[d]

vecf = np.vectorize(s2vec)
if list(vecf(list(s), s_dict)) == list(vecf(list(t), t_dict)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
import numpy as np
from collections import Counter
s=input()
t=input()
s1=set(s)
t1=set(t)
if s==t:
    print('Yes')
    sys.exit()
qu2=[]
if len(s1)==len(t1):
    for i in s1:
        if s.count(i)>1:
            qu=[j for j,e in enumerate(s) if e==i]
            for j in qu:
                j=int(j)
                qu2.append(t[j])
            qu3=set(qu2)
            if len(qu3)!=1:
                print('No')
                sys.exit()
            else:
                qu3.clear()
        qu2=[]
        qu=[]
    print('Yes')
elif len(s1)!=len(t1):
    print('No')

Submission status: Accepted

Solution code:
s, t = [input() for _ in range(2)]

while True:
    if s == "":
        break

    s = s.replace(s[0], "")
    t = t.replace(t[0], "")
    
    if len(s) != len(t):
        print("No")
        exit(0)

print("Yes")

Submission status: Accepted

Solution code:
a = list(input())
b = list(input())
c = len(a)
p = 0
d = [0 for i in range(27)]
l = [[]for i in range(27)]
h = [[]for i in range(27)]
ll = [0 for i in range(27)]
if a == b:
	print("Yes")
else:
	for i in range(c):
		k = ord(b[i])-97
		if a[i] in l[k]:
			p = 0
		else:
			if len(l[k]) == 0:
				l[k].append(a[i])
			else:
				p = 1
				break
		k = ord(a[i])-97
		if b[i] in h[k]:
			p = 0
		else:
			if len(h[k]) == 0:
				h[k].append(b[i])
			else:
				p = 1
				break
	if p == 1:
		print("No")
	else:
		print("Yes")

Submission status: Accepted

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

dict1 = {}
ls =[]
for i in range(len(S)):
    if S[i] not in dict1:
        dict1[S[i]] = i
    ls.append(dict1[S[i]])

dict2 = {}
lt =[]
for i in range(len(T)):
    if T[i] not in dict2:
        dict2[T[i]] = i
    lt.append(dict2[T[i]])

if ls == lt:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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



sl=list(s)

sl.sort()
sl=''.join(sl)

a=''
for i in range(n):
    if(sl[i]==a):continue
    a=sl[i]
    b=t[s.index(a)]
    s=s.translate(str.maketrans({a:b,b:a}))
    sl=sl.translate(str.maketrans({a:b,b:a}))
    

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

Submission status: Accepted

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

tdic = dict()
sdic = dict()
for i in range(len(S)):
    if T[i] in tdic:
        if tdic[T[i]] != S[i]:
            print("No")
            break
    else:
        tdic[T[i]] = S[i]

    if S[i] in sdic:
        if sdic[S[i]] != T[i]:
            print("No")
            break
    else:
        sdic[S[i]] = T[i]
else:
    print("Yes")

Submission status: Accepted

Solution code:
inputS = input()
arrayS = list(inputS)
arraySorted = list(inputS)
arraySorted.sort()
inputT = input()
arrayT = list(inputT)
arrayTSorted = list(inputT)
arrayTSorted.sort()

flagForA =0
# the same character search
index = 0
length = len(arrayS)
listForSame = []
while index < length-1:
    if arraySorted[index] == arraySorted[index+1]:
        if arraySorted[index] in listForSame:
            pass
        else:
            listForSame.append(arraySorted[index])
    index+=1
if listForSame == []:
    flagForA=1
else:
    flag =0
    listForSet =[]
    for caburi in listForSame:
        index2 =0
        listForAdd = []
        while index2 < length:
            if arrayS[index2] == caburi:
                listForAdd.append(index2)
            index2+=1
        listForSet.append(listForAdd)
    for everySet in listForSet:
        index3 =0
        while index3 < len(everySet)-1:
            if arrayT[everySet[index3]] == arrayT[everySet[index3+1]]:
                index3+=1
            else:
                flag =1
                flagForA=0
                break
    if flag ==0:
        flagForA=1
    else:
        flagForA=0

flagForB =0           
# the same character searchT
index = 0
length = len(arrayT)
listForSame2 = []
while index < length-1:
    if arrayTSorted[index] == arrayTSorted[index+1]:
        if arrayTSorted[index] in listForSame2:
            pass
        else:
            listForSame2.append(arrayTSorted[index])
    index+=1
if listForSame2 == []:
    flagForB=1
else:
    flag =0
    listForSet =[]
    for caburi in listForSame2:
        index2 =0
        listForAdd = []
        while index2 < length:
            if arrayT[index2] == caburi:
                listForAdd.append(index2)
            index2+=1
        listForSet.append(listForAdd)
    for everySet in listForSet:
        index3 =0
        while index3 < len(everySet)-1:
            if arrayS[everySet[index3]] == arrayS[everySet[index3+1]]:
                index3+=1
            else:
                flag =1
                flagForB=0
                break
    if flag ==0:
        flagForB=1
    else:
        flagForB=0

#all character used search
allUsedFlagS =0
allUsedFlagT =0
flagForC =1
if length > 25:
    for char in [chr(i) for i in range(97,97+26)]:
        if char in arraySorted:
            pass
        else:
            allUsedFlagS =1
            break
    for char in [chr(i) for i in range(97,97+26)]:
        if char in arrayTSorted:
            pass
        else:
            allUsedFlagT =1
            break
    if allUsedFlagS ==0 and allUsedFlagT ==0:
        alphaList = [chr(i) for i in range(97,97+26)]
        sosuuList = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103]
        numberS =1
        for char1 in arrayS:
            index1 = alphaList.index(char1)
            numberS*= sosuuList[index1]
        numberT =1
        for char2 in arrayT:
            index2 = alphaList.index(char2)
            numberT*= sosuuList[index2]
        if numberS!=numberT:
            flagForC=0
        else:
            flagForC=1

        
if flagForA ==1 and flagForB==1 and flagForC==1:
    print("Yes")  
else:
    print("No")