Problem:


Score : 300 points

Problem Statement

You are given strings S and T consisting of lowercase English letters.

You can perform the following operation on S any number of times:

Operation: Choose two distinct lowercase English letters c_1 and c_2, then replace every occurrence of c_1 with c_2, and every occurrence of c_2 with c_1.

Determine if S and T can be made equal by performing the operation zero or more times.

Constraints

1 \leq |S| \leq 2 \times 10^5

|S| = |T|

S and T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T

Output

If S and T can be made equal, print Yes; otherwise, print No.

Sample Input 1

azzel
apple

Sample Output 1

Yes

azzel can be changed to apple, as follows:

Choose e as c_1 and l as c_2. azzel becomes azzle.

Choose z as c_1 and p as c_2. azzle becomes apple.

Sample Input 2

chokudai
redcoder

Sample Output 2

No

No sequences of operation can change chokudai to redcoder.

Sample Input 3

abcdefghijklmnopqrstuvwxyz
ibyhqfrekavclxjstdwgpzmonu

Sample Output 3

Yes



Sample input:
azzel
apple


Sample output:
Yes

Submission status: Accepted

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

SS = sorted(list(S))
TT = sorted(list(T))
SSS = []
TTT = []
numS = 0
numT = 0
checkS = 1
checkT = 1

for i in range(len(S)-1):
    if SS[i] != SS[i+1]:
        SSS.append(checkS)
        checkS = 1
    elif i == len(S)-2:
        SSS.append(checkS+1)
    else:
        checkS += 1

    if TT[i] != TT[i+1]:
        TTT.append(checkT)
        checkT = 1
    elif i == len(S)-2:
        TTT.append(checkT+1)
    else:
        checkT += 1
SSS.sort()
TTT.sort()
if SSS == TTT:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import collections
s = input()
t = input()
dd = collections.defaultdict(str)
dd2 = collections.defaultdict(str)
for i in range(len(s)):
    if dd[t[i]] == '':
        dd[t[i]] = s[i]
    if dd[t[i]] != '' and dd[t[i]] != s[i]:
        print('No')
        exit()
for i in range(len(s)):
    if dd2[s[i]] == '':
        dd2[s[i]] = t[i]
    if dd2[s[i]] != '' and dd2[s[i]] != t[i]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import Counter
S = input()
T = input()
ans = "Yes"
s_dict = defaultdict(str)
t_dict = defaultdict(str)
# SとTが互いに単射であればYesそうでなければNo
for s,t in zip(S,T):
  if s_dict[t] != "" and s_dict[t] != s:
    ans = "No"
    break
  elif t_dict[s] != "" and t_dict[s] != t:
    ans = "No"
    break
  s_dict[t] = s
  t_dict[s] = t
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

s, t = input(), input()
sc, tc = list(Counter(s).values()), list(Counter(t).values())
sc.sort()
tc.sort()
if sc != tc:
  print('No')
  quit()
ss, tt = s[0], t[0]
for i, j in zip(s, t):
  if i == ss and j == tt:
    continue
  elif  i != ss and j != tt:
    ss, tt = i, j
  else:
    print('No')
    quit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import Counter

s, t = readline(), readline()
sc, tc = list(Counter(s).values()), list(Counter(t).values())
sc.sort()
tc.sort()
print('Yes' if sc == tc else 'No')

Submission status: Accepted

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

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()
T = input()

C1 = sorted(Counter(S).values())
C2 = sorted(Counter(T).values())

N = len(C1)
if len(C2) != N:
    No()
    exit()
for i in range(N):
    if C1[i] != C2[i]:
        No()
        exit()
Yes()

Submission status: Accepted

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

adic = {}
bdic = {}

for i in range(len(S)):
  if adic.get(S[i], T[i]) != T[i] or bdic.get(T[i], S[i]) != S[i]:
    print("No")
    exit()
  adic[S[i]] = T[i]
  bdic[T[i]] = S[i]

print("Yes")

Submission status: Accepted

Solution code:
from collections import defaultdict
S = input()
T = input()
dicta = defaultdict(set)
dictb = defaultdict(set)
for i in range(len(S)):
    dicta[S[i]].add(T[i])
    dictb[T[i]].add(S[i])

flag = True
for v in dicta.values():
    if len(v) != 1:
        flag = False
for v in dictb.values():
    if len(v) != 1:
        flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
A = list(input().rstrip())
B = list(input().rstrip())
N = len(A)
change_1 = [[0] * 26 for _ in range(26)]
change_2 = [[0] * 26 for _ in range(26)]
alpha2num = lambda c: ord(c) - ord("a")
for i, j in zip(A, B):
    change_1[alpha2num(i)][alpha2num(j)] += 1
change_1 = np.array(change_1)
for i, j in zip(B, A):
    change_2[alpha2num(i)][alpha2num(j)] += 1
change_2 = np.array(change_2)
for k in change_1:
    if np.count_nonzero(k) > 1:
        print("No")
        sys.exit()
for k in change_2:
    if np.count_nonzero(k) > 1:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
from collections import defaultdict


S = input()
T = input()
S_count = defaultdict(int)
T_count = defaultdict(int)

for s, t in zip(S, T):
    S_count[s] += 1
    T_count[t] += 1

A = list(S_count.values())
B = list(T_count.values())

A.sort()
B.sort()

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

Submission status: Accepted

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

d = {}

c = 0
for i in range(len(s)):
  if s[i] not in d:
    d[s[i]] = c
    c += 1

d_ = {}
used = set()
for i in range(len(t)):
  if t[i] not in d_ and s[i] not in used:
    d_[t[i]] = d[s[i]]
    used.add(s[i])
  elif t[i] not in d_ and s[i] in used:
    print('No')
    exit()
  else:
    pass

for i in range(len(s)):
  if d[s[i]] != d_[t[i]]:
    print('No')
    exit()
else:
  print('Yes')

Submission status: Accepted

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

w = [0 for _ in range(200)]

def ans():
    for s, t in zip(S, T):
        if w[ord(s)] > 0:
            # print("a", w[ord(s)], ord(t))
            if w[ord(s)] != ord(t):
                return("No")
        elif ord(t) in w:
            # print("b")
            return("No")

        w[ord(s)] = ord(t)
        

    for i in range(ord("a"), ord("z")):
        # print(i)
        if w[i] > 0:
            # print(chr(w[w[i]]), chr(i))
            tmp = w[i]
            tmp2 = w[i]
            while(True):
                if w[w[i]] !=0 and w[w[i]] != i:
                    r = w[w[i]]
                    w[w[i]] = w[i]
                    w[i] = r
                else:
                    break
                tmp = w[i]
                if tmp == tmp2:
                    return("No")
    return("Yes")

print(ans())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力
 
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
 
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
 
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    S = input()
    T = input()
    S = S[:-1]
    T = T[:-1]
    
    S_dict = {}
    T_dict = {}
    for i in range(len(S)):
        if S[i] in S_dict:
            S_dict[S[i]] += 1
        else:
            S_dict[S[i]] = 1
            
        if T[i] in T_dict:
            T_dict[T[i]] += 1
        else:
            T_dict[T[i]] = 1
            
    S_list = []
    T_list = []
    for k,v in S_dict.items():
        S_list.append(v)
    for k,v in T_dict.items():
        T_list.append(v)
        
    S_list.sort()
    T_list.sort()
    
    if S_list == T_list:
        print("Yes")
    else:
        print("No")
    #print(S_list)
    #print(T_list)
        
    
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = list(map(lambda x:ord(x)-97,input()))
t = list(map(lambda x:ord(x)-97,input()))

ret = "Yes"
transform_mapping = [[0] * 26 for _ in range(26)]

for si,ti in zip(s,t):
    transform_mapping[si][ti] = 1
for i in transform_mapping:
    if sum(i) >= 2:
        ret = "No"
for i in zip(*transform_mapping):
    if sum(i) >= 2:
        ret = "No"
print(ret)

Submission status: Accepted

Solution code:
def list_count(my_list):
    dic={} #辞書型の宣言
    for num in my_list:
        if num in dic: #もしnumがkeyとして辞書にあれば
            dic[num]+=1 #valueに+1
        else: #なければ
            dic[num]=1 #dicにnumというkeyを追加し、対応するvalueを1とする
    return dic
s=input()
t=input()
n=len(s)
dic={}
for i in range(n):
    if s[i] in dic and dic[s[i]]!=t[i]:
        print("No")
        exit()
    else:
        dic[s[i]]=t[i]
dic2={}
for i in range(n):
    if t[i] in dic2 and dic2[t[i]]!=s[i]:
        print("No")
        exit()
    else:
        dic2[t[i]]=s[i]
print("Yes")

Submission status: Accepted

Solution code:
from collections import Counter

S = input()
T = input()

a = sorted([i for i in Counter(S).values()])
b = sorted([i for i in Counter(T).values()])

if a == b: print('Yes')
else: print('No')

Submission status: Accepted

Solution code:
S=input();T=input()
for cap in range(ord("a"),ord("z")+1):
  c=chr(cap)
  list_s=[]
  for i in range(len(S)):
    if S[i]==c:
      list_s.append(i)
  
  list_t=[]
  if list_s != []:
    c=T[list_s[0]]  
    for i in range(len(T)):
      if T[i]==c:
        list_t.append(i)
        
  if list_s!=list_t:
    print("No");exit()
    
print("Yes")

Submission status: Accepted

Solution code:
import sys
from collections import Counter
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

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

cs = Counter(S).most_common()
ct = Counter(T).most_common()

N = len(cs)

vs, cs = zip(*cs)
vt, ct = zip(*ct)

#print(vs, cs, vt, ct)

for i,j in zip(cs, ct):
	if cs != ct:
		print('No')
		sys.exit()
print('Yes')

Submission status: Accepted

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

def cnvS(St):
  import re
  cnt = 0
  while (cnt < 26):
    fnd=re.search('[a-z]', St)
    if fnd:
      St = St.replace(fnd.group(),AL[cnt])
      cnt +=1
    else:
      break
  return St

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

Submission status: Accepted

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

pre_dict = {}
post_dict = {}
ans = True
for i in range(len(s_l)):
    if s_l[i] in pre_dict.keys():
        if t_l[i] not in pre_dict[s_l[i]]:
            ans = False
    else:
        pre_dict[s_l[i]] = [t_l[i]]
    
    if t_l[i] in post_dict.keys():
        if s_l[i] not in post_dict[t_l[i]]:
            ans = False
    else:
        post_dict[t_l[i]] = [s_l[i]]

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

Submission status: Accepted

Solution code:
import sys
s=input()
t=input()
n=len(s)
d=dict()
d2=dict()
for i in range(n):
    if t[i] in d.keys():
        if d[t[i]] != s[i]:
            print("No")
            sys.exit()
    else:
        d[t[i]] = s[i]
    
    if s[i] in d2.keys():
        if d2[s[i]] != t[i]:
            print("No")
            sys.exit()
    else:
        d2[s[i]] = t[i]
else:
    print("Yes")

Submission status: Accepted

Solution code:
S = input()
T = input()
ans = "Yes"
start = [-1]*26
goal = [-1]*26
for i in range(len(S)):
    s,t = ord(S[i])-97,ord(T[i])-97
    if start[s]!=-1 or goal[t]!=-1:
        if start[s]!=t or goal[t]!=s:
            ans = "No"
    else:
        start[s] = t
        goal[t] = s
print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
ans = "Yes"
start = [-1]*27
goal = [-1]*27
for i in range(len(S)):
    s,t = ord(S[i])-96,ord(T[i])-96
    if start[s]!=-1 or goal[t]!=-1:
        if start[s]!=t or goal[t]!=s:
            ans = "No"
    else:
        start[s] = t
        goal[t] = s
print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
D = dict()
f = True
for s, t in zip(S, T):
  if s not in D:
    if t not in D.values():
    	D[s] = t
    else:
      f = False
      break
  elif D[s] != t:
    f = False
    break
print('Yes' if f else 'No')

Submission status: Accepted

Solution code:
s=list(input())
t=list(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:
from collections import Counter

s = input()
t = input()

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

if len(sc) != len(tc):
    print("No")
    exit()

S,T = [],[]
for s,t in zip(sc.values(),tc.values()):
    S.append(s)
    T.append(t)

S.sort()
T.sort()

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

Submission status: Accepted

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

def checking(check_dict, key, val, yes_ans):
    if key in check_dict:
        if check_dict[key] == val:
            pass
        else:
            print('No')
            yes_ans = False
            return yes_ans
    else:
        check_dict[key] = val
    return yes_ans


t_dict = {}
s_dict = {}
yes_ans = True

for t_val, s_val in zip(t, s):
    yes_ans = checking(t_dict, t_val, s_val, yes_ans)
    if yes_ans == False:
        break
    yes_ans = checking(s_dict, s_val, t_val, yes_ans)
    if yes_ans == False:
        break

if yes_ans:
    print('Yes')

Submission status: Accepted

Solution code:
S=str(input())
T=str(input())
x=[]
y=[]
dic={}

for i in range(len(S)):
    x.append(S[i])
    y.append(T[i])
    
for s,t in zip(x,y):
    if s in dic:
        if dic[s]!=t:
            print("No")
            exit()
    else:
        dic[s]=t

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

Submission status: Accepted

Solution code:
S=input()
T=input()
S2=[0]*len(S)
T2=[0]*len(T)
SD={}
TD={}

c=0
for i in range(len(S)):
    if(SD.get(S[i],None)==None):
        c+=1
        SD[S[i]]=c
        S2[i]=c
    else:
        S2[i]=SD.get(S[i],None)
c=0
for i in range(len(T)):
    if(TD.get(T[i],None)==None):
        c+=1
        TD[T[i]]=c
        T2[i]=c
    else:
        T2[i]=TD.get(T[i],None)
if(S2==T2):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
s=input()
t=input()
l=len(s)
c=[chr(i) for i in range(97,97+26)]
for i in range(26):
    f=0
    for j in range(l):
        if c[i]==s[j]:
            if f==0:
                k=t[j]
                f+=1
            elif f==1 and t[j]!=k:
                f+=1
                print("No")
                break
    if f==2:
        break
else:
    for i in range(26):
        f=0
        for j in range(l):
            if c[i]==t[j]:
                if f==0:
                    k=s[j]
                    f+=1
                elif f==1 and s[j]!=k:
                    f+=1
                    print("No")
                    break
        if f==2:
            break
    else:
        print("Yes")

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
dic = {}
ans='Yes'
for s,t in zip(S,T):
  if not s in dic:
    if t in dic.values():
      ans = 'No'
      break
    else:
      dic[s]=t
    
  else:
    if dic[s]!=t:
      ans = 'No'
      break
      
print(ans)

Submission status: Accepted

Solution code:
a=input()
b=input()
c={}
state=True
for i in range(len(a)):
  if b[i] not in c and a[i] not in c.values():
    c[b[i]]=a[i]
  if b[i] in c:
    if c[b[i]]!=a[i]:
      state=False
  else:
    state=False
if state:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s = list(input())
del s[-1]
t = list(input())
del t[-1]


table_s = [-1]*26
table_t = [-1]*26

for i in range(len(s)):
    if table_s[ord(s[i])-ord("a")] == -1:
        table_s[ord(s[i])-ord("a")] = ord(t[i])-ord("a")
        table_t[ord(t[i])-ord("a")] = ord(s[i])-ord("a")
    else:
        if table_s[ord(s[i])-ord("a")] != ord(t[i])-ord("a"):
            print("No")
            exit()

table_s = [-1]*26
table_t = [-1]*26

for i in range(len(t)):
    if table_t[ord(t[i])-ord("a")] == -1:
        table_t[ord(t[i])-ord("a")] = ord(s[i])-ord("a")
        table_s[ord(s[i])-ord("a")] = ord(t[i])-ord("a")
    else:
        if table_t[ord(t[i])-ord("a")] != ord(s[i])-ord("a"):
            print("No")
            exit()


print("Yes")

Submission status: Accepted

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

from collections import Counter as c
s = c(S)
t = c(T)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

s=input()
t=input()
ds=collections.defaultdict(set)
dt=collections.defaultdict(set)

for i in range(len(s)):
    ds[s[i]].add(t[i])
    dt[t[i]].add(s[i])

for si in ds.values():
    if len(si)>=2:
        print("No")
        exit()

for ti in dt.values():
    if len(ti)>=2:
        print("No")
        exit()

print("Yes")
# for i,e in d.items():
#     print(i,e)

Submission status: Accepted

Solution code:
s = input()
t = input()
sWords = {}
tWords = {}
for si, ti in zip(s,t):
    sWords[si] = sWords.get(si, 0) + 1
    tWords[ti] = tWords.get(ti, 0) + 1
print(["No", "Yes"][sorted(list(sWords.values())) == sorted(list(tWords.values()))])

Submission status: Accepted

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

start = [-1]*26
goal = [-1]*26

temp = 0

for i in range(len(S)):
    a = ord(S[i]) - ord("a")
    b = ord(T[i]) - ord("a")

    if (b in start or a in goal):
        if (start[a] != b or goal[b] != a):
            temp = 1
            break
    else:
        start[a] = b
        goal[b] = a

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

Submission status: Accepted

Solution code:
d={}
w1=input()
w2=input()
num=len(w1)
b=True
for i in list("qwertyuiopasdfghjklzxcvbnm"):
  d[i]=""
for i in range(num):
  if d[w1[i]]=="":
    d[w1[i]]=w2[i]
  elif d[w1[i]]==w2[i]:
    pass
  elif d[w1[i]]!=w2[i]:
    b=False
    break
if not b:
  print("No")
else:
  l=[]
  for i in d:
    if d[i] in l:
      b=False
      break
    else:
      if d[i]!="":
        l.append(d[i])
  if b:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
now = 0
idxS_dict = {}
idxT_dict = {}
for i in range(26):
    idxS_dict[chr(ord('a') + i)] = []
    idxT_dict[chr(ord('a') + i)] = []
for i in range(len(S)):
    idxS_dict[S[i]].append(i)
    idxT_dict[T[i]].append(i)

S_vals = idxS_dict.values()
T_vals = idxT_dict.values()

for val in S_vals:
    if not val in T_vals:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

dicS = defaultdict(int)
dicT = defaultdict(int)
for s, t in zip(S, T):
    dicS[s] += 1
    dicT[t] += 1
    if dicS[s] != dicT[t]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

ascii_lower = list(string.ascii_lowercase)
s_list = [-1 for _ in range(26)]
t_list = s_list[:]


for s, t in zip(S, T):
  s_index = ascii_lower.index(s)
  t_index = ascii_lower.index(t)
  
  if s_list[s_index] != -1 or t_list[t_index] != -1:
    if s_list[s_index] != t_index or t_list[t_index] != s_index:
      print('No')
      break
  s_list[s_index] = t_index
  t_list[t_index] = s_index
else:
  print('Yes')

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
slis = [None]*26
tlis = [None]*26
for s,t in zip(S,T):
    sn = ord(s) - 97
    tn = ord(t) - 97
    if slis[sn] == None and tlis[tn] == None:
        slis[sn] = tn
        tlis[tn] = sn
    else:
        if slis[sn] == tn and tlis[tn] == sn:
            continue
        else:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

S = input().strip()
T = input().strip()
dic = {}

for s, t in zip(S, T):
    if s not in dic:
        dic[s] = t
    elif dic[s] != t:
        print('No')
        exit()

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

Submission status: Accepted

Solution code:
s=list(input())
t=list(input())
al=lambda x:ord(x)-ord("a")+1 #文字に番号つける　aなら1.zなら26
moji=[0]*27 #その番号の文字は一致してるか 最初の０は数合わせ
moji_num=0 #文字の種類
l=len(s)
ans="Yes"
for i in range(l): #s,tで一致してるもの探す。
    if s[i]==t[i]:
        index=al(s[i])
        if moji[index]==0:
            moji[index]=1
            moji_num+=1
        if moji_num==26:
            break
            
want=[[] for i in range(27)] #その番号の文字がなりたい文字
wanted=[[] for i in range(27)] #その番号の文字になりたい文字
for i in range(l):
    s_str=s[i] #変えるかもしれない文字
    t_str=t[i]
    if s_str!=t_str:
        index1=al(s_str)
        index2=al(t_str)
        if moji[index1]==1 or moji[index2]==1: 
            ans="No"
            #print(i)
            break
        if len(want[index1])!=0: #もうなりたい文字がある
            if want[index1][0]!=t_str:
                ans="No"
                #print(i)
                break
        want[index1].append(t_str)
        if len(wanted[index2])!=0: #もうこの文字になりたい文字がいる
            if wanted[index2][0]!=s_str:
                ans="No"
                #print(i)
                break
        wanted[index2].append(s_str)
print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
d = {}
for s,t in zip(S,T):
    if s in d:
        if d[s] != t:
            print('No')
            exit()
    else:
        d[s] = t

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

Submission status: Accepted

Solution code:
S = input()
T = input()
s_dict = {}
for s in S:
    if s in s_dict:
        s_dict[s] += 1
    else:
        s_dict[s] = 1
t_dict = {}
for t in T:
    if t in t_dict:
        t_dict[t] += 1
    else:
        t_dict[t] = 1

ss = list(s_dict.values())
ss.sort()
#ss = list(s_dict.values()).sort()
tt = list(t_dict.values())
tt.sort()
# print(ss)
# print(tt)
if ss == tt:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s = str(input())
t = str(input())
slist = []*len(s)
scnt = 0
tlist = []*len(t)
tcnt = 0
ans='Yes'
i=0
while i < len(s):
    inds = s.index(s[i])
    indt = t.index(t[i])
    if inds < i:
        slist.append(slist[inds])
    else:
        slist.append(scnt)
        scnt+=1
    if indt < i:
        tlist.append(tlist[indt])
    else:
        tlist.append(tcnt)
        tcnt+=1
    if slist[i]!=tlist[i]:
        ans='No'
        break
    i+=1
print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
dict_st = {}
dict_ts = {}
N = len(S)
for i in range(N):
    if S[i] not in dict_st:
        dict_st[S[i]] = T[i]
    else:
        if dict_st[S[i]] != T[i]:
            print("No")
            exit()
for i in range(N):
    if T[i] not in dict_ts:
        dict_ts[T[i]] = S[i]
    else:
        if dict_ts[T[i]] != S[i]:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
s = input()
t = input()
dict_st = {}
dict_ts = {}
for x, y in zip(s, t):
    if x not in dict_st:
        dict_st[x] = y
    else:
        if dict_st[x] != y:
            print("No")
            break
    if y not in dict_ts:
        dict_ts[y] = x
    else:
        if dict_ts[y] != x:
            print("No")
            break
else:
    print("Yes")

Submission status: Accepted

Solution code:
from collections import Counter
 
S = list(input())
T = list(input())
 
SS = Counter(S)
TT = Counter(T)
 
SS = list(SS.values())
SS.sort()
 
TT = list(TT.values())
TT.sort()
 
if SS == TT:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
s=input()
t=input()
import sys
from collections import defaultdict
dic1=defaultdict(lambda:'A')
dic2=defaultdict(lambda:'B')
ans=1
for i in range(len(s)):
  if s[i] in dic1 or t[i] in dic2:
    if dic1[s[i]]==t[i] and  dic2[t[i]]==s[i]:
      pass
    else:
      print('No')
      quit()
  else:
    dic1[s[i]]=t[i]
    dic2[t[i]]=s[i]
print('Yes')

Submission status: Accepted

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

replace_to =[]
flag = False
for i in range(len(S)):
    if S[i] != T[i]:
        if S[i] in replace_to or T[i] in replace_to:
            flag = True
            break
        else:
            S = S.replace(T[i], '0').replace(S[i], T[i]).replace('0', S[i])
            replace_to.append(S[i])

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

Submission status: Accepted

Solution code:
import numpy as np


def solve(s, t):
    u = np.array([0]*26)
    v = np.array([0]*26)

    for si in s:
        u[ord(si)-97] += 1
    for ti in t:
        v[ord(ti)-97] += 1
    u.sort()
    v.sort()
    for i in range(26):
        if u[i] - v[i] != 0:
            return False

    return True


if __name__ == '__main__':
    s = input()
    t = input()
    ans = 'Yes' if solve(s, t)else 'No'
    print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    s = list(input())
    t = list(input())
    n = len(s)
    s_dict = defaultdict(int)
    t_dict = defaultdict(int)
    for i in range(n):
        s_dict[s[i]] += 1
        t_dict[t[i]] += 1

    #print(s_dict)
    #print(t_dict)

    if sorted(list(s_dict.values()))== sorted(list(t_dict.values())):
        print('Yes')
    else:
        print('No')
        

if  __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
T = input()

dic = defaultdict(int)
dic2 = defaultdict(int)

for i in S:
	dic[i] += 1

for j in T:
	dic2[j] += 1

for i, j in zip(sorted(dic.values()), sorted(dic2.values())):
	if i != j:
		print("No")
		break
else:
	print("Yes")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = input()
T = input()

import collections
trans_dicts1 = collections.defaultdict(set)
trans_dicts2 = collections.defaultdict(set)
for s, t in zip(S, T):
    # if s != t:
    trans_dicts1[s].add(t)
    trans_dicts2[t].add(s)

n1 = max(map(len, trans_dicts1.values()))
n2 = max(map(len, trans_dicts2.values()))

if n1 == 1 and n2 == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

slist=[]
tlist=[]
#sとtそれぞれ、a～zがそれぞれ何個ずつあるか記録した配列。

for i in range(26):
  c=chr(i+ord("a"))
  temp1=s.count(c)
  temp2=t.count(c)
  slist.append(temp1)
  tlist.append(temp2)


sbetsu=[]
tbetsu=[]

for i in s:
  sbetsu.append(slist[ord(i)-97])
for i in t:
  tbetsu.append(tlist[ord(i)-97])



if sbetsu==tbetsu:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
from collections import defaultdict
s = input()
t = input()
ds = defaultdict(list)
dt = defaultdict(list)
for i in range(len(s)):
  ds[s[i]].append(i)
  dt[t[i]].append(i)
dss = set()
dts = set()
for i in ds.values():
  dss.add(tuple(i))
for i in dt.values():
  dts.add(tuple(i))
print('YNeos'[dss!=dts::2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline=sys.stdin.buffer.readline

S=readline().rstrip().decode("utf-8")
T=readline().rstrip().decode("utf-8")

S2T=[[0 for i in range(26)] for j in range(26)]
T2S=[[0 for i in range(26)] for j in range(26)]

for i in range(len(S)):
  s,t=ord(S[i])-97,ord(T[i])-97
  S2T[s][t]+=1
  T2S[t][s]+=1
#print("S2T:",S2T)

for i in range(26):
  cnt=0
  for j in range(26):
    if S2T[i][j]>0:
      cnt+=1
      if cnt>1:
        print("No")
        exit()
  cnt=0
  for j in range(26):
    if T2S[i][j]>0:
      cnt+=1
      if cnt>1:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
def main():
    S = input()
    T = input()
    from collections import defaultdict
    st_dic = defaultdict(set)
    ts_dic = defaultdict(set)
    for s, t in zip(S, T):
        st_dic[s].add(t)
        ts_dic[t].add(s)
        if len(st_dic[s]) > 1 or len(ts_dic[t]) > 1:
            return print("No")
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

con = 0

ans = "Yes"

for i in range(0,len(S)):
  for j in range(0,i):
    if T[i] == T[j]:
      if S[i] != S[j]:
        ans = "No"
        break
      break
    if S[i] == S[j]:
      if T[i] != T[j]:
        ans = "No"
        break
      break


print(ans)