Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

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

|S| = |T|

S and T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T

Output

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

Sample Input 1

azzel
apple

Sample Output 1

Yes

azzel can be changed to apple, as follows:

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

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

Sample Input 2

chokudai
redcoder

Sample Output 2

No

No sequences of operation can change chokudai to redcoder.

Sample Input 3

abcdefghijklmnopqrstuvwxyz
ibyhqfrekavclxjstdwgpzmonu

Sample Output 3

Yes



Sample input:
azzel
apple


Sample output:
Yes

Submission status: Accepted

Solution code:
from collections import Counter

s, t = input(), input()

dict = {}
for si, ti in zip(s, t):
    if ti not in dict:
        dict[ti] = si
    elif dict[ti] != si:
        print('No')
        break
else:
    cnt = Counter(dict.values())
    bool = all(cnt[i] <= 1 for i in cnt)
    print('Yes' if bool else 'No')

Submission status: Accepted

Solution code:
from collections import defaultdict

s = input()
t = input()

dicts = defaultdict(int)
dictt = defaultdict(int)

cs = []
ct = []

for i in range(len(s)):
    dicts[s[i]] += 1
    dictt[t[i]] += 1
    cs.append(dicts[s[i]])
    ct.append(dictt[t[i]])


if cs == ct:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
T = input()
N = len(S)
count = 0
R_1 = [-1 for i in range(26)]
R_2 = [-1 for i in range(26)]

answer = "Yes"
for i in range(N):
    r1 = ord(S[i]) - 97
    r2 = ord(T[i]) - 97
    if R_1[r1] >= 0:
        if r2 != R_1[r1]:
            answer = "No"
            break
    if R_2[r2] >= 0:
        if r1 != R_2[r2]:
            answer = "No"
            break
    if R_1[r1] < 0:
        R_1[r1] = r2
    if R_2[r2] < 0:
        R_2[r2] = r1
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
S    = np.array(list(input()))
T    = np.array(list(input()))
N    = len(S)
SSrt = np.sort(S)
TSrt = np.sort(T)
SArg = np.argsort(S)
TArg = np.argsort(T)
SAgT = S[TArg]
TAgS = T[SArg]

SBef = ''
TBef = ''
SFlag = True
for ST in range(0,N):
    SNow = SSrt[ST]
    TNow = TAgS[ST]
    if SBef==SNow:
        if TBef!=TNow:
            SFlag = False
            break
    SBef = SNow
    TBef = TNow
        
SBef = ''
TBef = ''
TFlag = True
for TT in range(0,N):
    SNow = SAgT[TT]
    TNow = TSrt[TT]
    if TBef==TNow:
        if SBef!=SNow:
            TFlag = False
            break
    SBef = SNow
    TBef = TNow
        
if SFlag and TFlag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
S = input()
T = input()
a_idx = ord('a')
S_Lis = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [],
         13: [], 14: [], 15: [], 16: [], 17: [], 18: [], 19: [], 20: [], 21: [], 22: [], 23: [], 24: [], 25: []}
T_Lis = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [],
         13: [], 14: [], 15: [], 16: [], 17: [], 18: [], 19: [], 20: [], 21: [], 22: [], 23: [], 24: [], 25: []}
leng = len(S)
for i in range(leng):
    S_Lis[ord(S[i]) - a_idx].append(i)
    T_Lis[ord(T[i]) - a_idx].append(i)
if sorted(S_Lis.values()) == sorted(T_Lis.values()):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

dcs = {}
dct = {}
for i, s in enumerate(S):
    if s in dcs and dcs[s] != T[i]:
        print("No")
        exit()
    else:
        dcs[s] = T[i]
else:
    for j, t in enumerate(T):
        if t in dct and dct[t] != S[j]:
            print("No")
            exit()
        else:
            dct[t] = S[j]
    else:
        print("Yes")

Submission status: Accepted

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

S_count = Counter(S)
T_count = Counter(T)

d_S = defaultdict(int)
d_T = defaultdict(int)
for i in range(len(S)):
    d_S[S_count[S[i]]] += 1
    d_T[T_count[T[i]]] += 1

if (d_S == d_T):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s1,s2=input(),input()
d1,d2={},{}
for i,j in zip(s1,s2):
  if i not in d1:
    d1[i]=1
  else:
    d1[i]+=1
  if j not in d2:
    d2[j]=1
  else:
    d2[j]+=1
d1=sorted(d1.items(),key=lambda x:x[1])
d2=sorted(d2.items(),key=lambda x:x[1])
for i,j in zip(d1,d2):
  if i[1]!=j[1]:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	S = input()
	T = input()

	set_S = set(S)
	set_T = set(T)
	if len(set_S) != len(set_T):
		print("No")
		exit()

	dic = dict()

	flg = True
	for x,y in zip(S,T):
		if x not in dic:
			dic[x] = y
		else:
			if dic[x] != y:
				flg = False
				break
	
	if flg :
		print("Yes")
	else:
		print("No")

Submission status: Accepted

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

n = len(s)
d = {}
d2 = {}

for i in range(n):
    if s[i] not in d:
        d[s[i]] = t[i]
    elif d[s[i]] != t[i]:
        print("No")
        exit()
    if t[i] not in d2:
        d2[t[i]] = s[i]
    elif d2[t[i]] != s[i]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

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

d = {}
d2 = {}
for i in range(len(S)):
  if not d.get(S[i]):
    d[S[i]] = T[i]
  elif d[S[i]] != T[i]:
    print('No')
    exit()
  if not d2.get(T[i]):
    d2[T[i]] = S[i]
  elif d2[T[i]] != S[i]:
    print('No')
    exit()

print('Yes')

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    S = [item for item in input()]
    T = [item for item in input()]

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


    if sorted(S_cnt.values()) == sorted(T_cnt.values()):
            print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
"""
S = chokudai
T = redcoder

'redcoder' には 'e' が２つあるので一度に変える必要があるが、
Sではそれに相当する場所には 'h' と 'a' の2種類の文字があるので不可能。
こういう感じで一文字ずつ見ていけばよさそう。

10 ** 5なのでstring.count()とか使っちゃうとTLEしそう。

文字の出現回数を格納するリストを作っていって、それぞれ比較すればよさそう。
上の例だと、
    s_li = [1, 1, 1, 1, 1, 1, 1, 1]
    t_li = [2, 2, 2, 1, 1, 2, 2, 2]
になり、s_liとt_liの中身が異なるのでNG。
"""
from collections import defaultdict

S = input()
T = input()
s_li = [0] * len(S)   # 文字列Sに登場する文字の出現回数を順番に格納する
t_li = [0] * len(T)   # 文字列Tに登場する文字の出現回数を順番に格納する

# s_liを作っていく
s_cnt_dict = defaultdict(int)   # 文字ごとに出現回数をメモしていく
s_idx_dict = defaultdict(list)  # 同じ文字が出現するインデックスをメモしていく
for i in range(len(S)):
    k = S[i]
    s_cnt_dict[k] += 1
    s_idx_dict[k].append(i)
for k in s_cnt_dict:
    for idx in s_idx_dict[k]:
        s_li[idx] = s_cnt_dict[k]

# t_liを作っていく
t_cnt_dict = defaultdict(int)   # 文字ごとに出現回数をメモしていく
t_idx_dict = defaultdict(list)  # 同じ文字が出現するインデックスをメモしていく
for i in range(len(T)):
    k = T[i]
    t_cnt_dict[k] += 1
    t_idx_dict[k].append(i)
for k in t_cnt_dict:
    for idx in t_idx_dict[k]:
        t_li[idx] = t_cnt_dict[k]

print('Yes') if s_li == t_li else print('No')

Submission status: Accepted

Solution code:
S = input()
T = input()
a_idx = ord('a')
S_Lis = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [],
         13: [], 14: [], 15: [], 16: [], 17: [], 18: [], 19: [], 20: [], 21: [], 22: [], 23: [], 24: [], 25: []}
T_Lis = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [],
         13: [], 14: [], 15: [], 16: [], 17: [], 18: [], 19: [], 20: [], 21: [], 22: [], 23: [], 24: [], 25: []}
leng = len(S)
for i in range(leng):
    S_Lis[ord(S[i])-a_idx].append(i)
    T_Lis[ord(T[i])-a_idx].append(i)
for i in range(26):
    tmpS = S_Lis[i]
    if len(tmpS) == 0 or tmpS == T_Lis[i]:
        continue
    else:
        flag = True
        for j in T_Lis.values():
            if tmpS == j:
                flag = False
                break
        if flag:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
from collections import defaultdict
s=list(input())
t=list(input())
change_st=defaultdict(int)
change_ts=defaultdict(int)
for i in range(len(s)):
    if change_st[s[i]]==0:
        change_st[s[i]]=t[i]
    else:
        if change_st[s[i]]!=t[i]:
            print("No")
            break
    if change_ts[t[i]]==0:
        change_ts[t[i]]=s[i]
    else:
        if change_ts[t[i]]!=s[i]:
            print("No")
            break
else:
    print("Yes")

Submission status: Accepted

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

n = len(s)
n = len(s)
a = [-1]*26
b = [-1]*26
flg = True

for i in range(n):
    snum = ord(s[i]) - 97
    tnum = ord(t[i]) - 97
    if a[snum] >= 0 and a[snum] != tnum:
        flg = False
        break
    if b[tnum] >= 0 and b[tnum] != snum:
        flg = False
        break
    if a[snum] == -1:
        a[snum] = tnum
    if b[tnum] == -1:
        b[tnum] = snum
    
print('Yes') if flg else print('No')

Submission status: Accepted

Solution code:

from collections import defaultdict

S = input()
T = input()
N = len(S)

SD = defaultdict(set)
TD = defaultdict(set)

for i in range(N):
  SD[S[i]].add(T[i])
  TD[T[i]].add(S[i])

cnt = 0

for i in SD.values():
  cnt = max(cnt, len(i))

for i in TD.values():
  cnt = max(cnt, len(i))

if cnt >= 2:
  print("No")
else:
  print("Yes")

Submission status: Accepted

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

S_d = dict()
T_d = dict()
for i in range(len(S)):
    S_d.setdefault(S[i], T[i])
    if S_d[S[i]] != T[i]:
        print('No')
        exit(0)
    T_d.setdefault(T[i], S[i])
    if T_d[T[i]] != S[i]:
        print('No')
        exit(0)
print('Yes')

Submission status: Accepted

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

# C - String Transformation /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 英小文字のみからなる文字列 S, Tが与えられます。
# 文字列 Sに対して、次の操作を何度でも行うことができます。
# 操作: 2つの異なる英小文字 c1, c2 を選び、S に含まれる全ての c1 を c2 に、c2 を c1に置き換える
# 0回以上操作を行って、S を Tに一致させられるか判定してください。

# 制約
#     1≤|S|≤2×10^5
#     |S|=|T|
#     S, Tは英小文字のみからなる

# 入力
# 入力は以下の形式で標準入力から与えられる。
# S
# T

# 出力
# Sを Tに一致させられる場合は Yes、そうでない場合は No を出力せよ。

# 入力例 1
# azzel
# apple

# 出力例 1
# Yes

# 次のように操作を行えば、azzel を apple にできます。
#     c1として e を、c2として l を選ぶと、azzel が azzle になる
#     c1として z を、c2として p を選ぶと、azzle が apple になる

# 入力例 2
# chokudai
# redcoder

# 出力例 2
# No

# どのように操作を行っても chokudai を redcoder にできません。

# 入力例 3
# abcdefghijklmnopqrstuvwxyz
# ibyhqfrekavclxjstdwgpzmonu

# 出力例 3
# Yes


def calculation(lines):
    # N = int(lines[0])
    # X, Y = list(map(int, lines[0].split()))
    S = lines[0]
    T = lines[1]
    ns = list()
    nt = list()
    for c in 'abcdefghijklmnopqrstuvwxyz':
        s = len(S) - len(S.replace(c, ''))
        ns.append(s)
        t = len(T) - len(T.replace(c, ''))
        nt.append(t)
    ns.sort()
    nt.sort()
    if ns == nt:
        return ['Yes']
    else:
        return ['No']


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['azzel', 'apple']
        lines_export = ['Yes']
    if pattern == 2:
        lines_input = ['chokudai', 'redcoder']
        lines_export = ['No']
    if pattern == 3:
        lines_input = ['abcdefghijklmnopqrstuvwxyz', 'ibyhqfrekavclxjstdwgpzmonu']
        lines_export = ['Yes']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
t = input()
S = sorted(map(s.count,set(s)))
T = sorted(map(t.count,set(t)))

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

Submission status: Accepted

Solution code:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    s = input()
    t = input()
    for i in range(len(s)):
        if s.index(s[i]) != t.index(t[i]):
            print('No')
            return
    print('Yes')
        
        
        
            
        
    
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
s=Counter(input()).most_common()
t=Counter(input()).most_common()
ans="Yes"
for i in range(min(len(s),len(t))):
  if s[i][1]!=t[i][1]:
    ans="No"
print(ans)

Submission status: Accepted

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

if len(set(S)) != len(set(T)):
    print("No")
    exit()
else:
    for i in range(len(S)):
        if S.index(S[i]) != T.index(T[i]):
            print("No")
            #print(S.index(S[i]), T.index(T[i]))
            exit()
print("Yes")

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
s=input()
t=input()
n=len(s)
x={}
y={}
for i in range(n):
    if s[i] not in x:
        x[s[i]]=set([i])
    else:
        x[s[i]].add(i)
    if t[i] not in y:
        y[t[i]]=set([i])
    else:
        y[t[i]].add(i)
a=set()
b=set()
for i in x.values():
  if i not in y.values():
    print("No")
    break
else:
  print("Yes")

Submission status: Accepted

Solution code:
# 初期入力
from collections import defaultdict
import sys
#input = sys.stdin.readline  #文字列では使わない
S =list(input())
T =list(input())

#
S_conversion =defaultdict(str)
T_conversion =defaultdict(str)
ans ="Yes"
if S ==T:
    ans ="Yes"
else:
    for i in range(len(S)):
        if S_conversion[S[i]] =="" and T_conversion[T[i]] =="":
            S_conversion[S[i]] =T[i] 
            T_conversion[T[i]] =S[i]
        elif S_conversion[S[i]] ==T[i]:
            continue
        elif T_conversion[T[i]] ==S[i]:
            continue
        else:
            ans ="No"
            #print(i)
            break
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n, m = [int(x) for x in input().split()]
    s = input()
    t = input()
    n = len(s)
    d = defaultdict(set)
    for i in range(n-1):
        if t[i] != t[i+1] and s[i] == s[i+1]:
            print("No")
            return
        d[t[i]].add(s[i])
    d[t[-1]].add(s[-1])

    for c in d:
        if len(d[c]) > 1:
            print("No")
            return
            
    print("Yes")
        

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""
a b a
d c d
a b a
"""

Submission status: Accepted

Solution code:
from string import ascii_lowercase
import sys
input=sys.stdin.readline
s=input().rstrip()
t=input().rstrip()
for alp in ascii_lowercase:
    switch=0
    for i in range(len(s)):
        if switch==0:
            if s[i]==alp:
                rem=t[i]
                switch=1
        else:
            if s[i]==alp:
                if t[i]!=rem:
                    print("No")
                    exit()
for alp in ascii_lowercase:
    switch=0
    for i in range(len(s)):
        if switch==0:
            if t[i]==alp:
                rem=s[i]
                switch=1
        else:
            if t[i]==alp:
                if s[i]!=rem:
                    print("No")
                    exit()
print("Yes")

Submission status: Accepted

Solution code:
ss,tt = open(0).read().split()

from collections import defaultdict

d = defaultdict(str)
e = defaultdict(str)
ans = 'Yes'
for s,t in zip(ss,tt):
    if not d[s]:
        d[s] = t
    elif d[s] != t:
        ans = 'No'
        break
    if not e[t]:
        e[t] = s
    elif e[t] != s:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

S = input()
T = input()

s_dic = defaultdict(list)
t_dic = defaultdict(list)


for i, ch in enumerate(S):
    s_dic[ch].append(i)

for i, ch in enumerate(T):
    t_dic[ch].append(i)

lis_s = list(s_dic.values())
lis_t = list(t_dic.values())

for i in range(len(lis_s)):
    if lis_s[i] != lis_t[i]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

S = input()
T = input()

x = defaultdict(list)
y = defaultdict(list)

for i, t in enumerate(T):
    x[t].append(S[i])

for i, s in enumerate(S):
    y[s].append(T[i])

ok = True
for k, v in x.items():
    a = v[0]
    for c in v:
        if c != a:
            ok = False
            break

for k, v in y.items():
    a = v[0]
    for c in v:
        if c != a:
            ok = False
            break

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

Submission status: Accepted

Solution code:
S1 = input()
S2 = input()

ss1 = {}
ss2 = {}
N = len(S1)
for i in range(N):
    if S1[i] not in ss1.keys():
        ss1[S1[i]] = S2[i]
    elif ss1[S1[i]] != S2[i]:
        print('No')
        exit(0)
    if S2[i] not in ss2.keys():
        ss2[S2[i]] = S1[i]
    elif ss2[S2[i]] != S1[i]:
        print('No')
        exit(0)

print('Yes')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def check_two_str(A, B):
    AtoB_dict = {}
    answer = True
    for i in range(len(A)):
        try:
            AtoB_dict[A[i]]
        except KeyError:
            AtoB_dict[A[i]] = B[i]
        else:
            if AtoB_dict[A[i]] != B[i]:
                answer = False
                break
    return answer

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
S = input()
T = input()
tmp1 = [set() for i in range(26)]
tmp2 = [set() for i in range(26)]
alpha2num = lambda c: ord(c) - ord('a')
for i in range(len(S)):
    tmp1[alpha2num(S[i])].add(T[i])
    tmp2[alpha2num(T[i])].add(S[i])
for i in range(26):
    if len(tmp1[i]) > 1 or len(tmp2[i]) > 1:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
# 基本的には一文字ずつ変えていけば変わるはずだがある一つの文字に複数の別の文字が当たってると変換できない
# chokudai
# redkuoai
# redcouai
# reucodai
# raucodei
# iaucoder

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

from collections import defaultdict
s_dic = defaultdict(set)
t_dic = defaultdict(set)
for i in range(len(S)):
    s = S[i]
    t = T[i]
    if len(s_dic[s]) > 0 and t not in s_dic[s]:
        print('No')
        exit()
    if len(t_dic[t]) > 0 and s not in t_dic[t]:
        print('No')
        exit()
    s_dic[s].add(t)
    t_dic[t].add(s)

print('Yes')

Submission status: Accepted

Solution code:
from collections import defaultdict
 
S = list(input())
T = list(input())
ds = defaultdict(int)
dt = defaultdict(int)
cnt_s = []
cnt_t = []
for s, t in zip(S, T):
    ds[s] += 1
    dt[t] += 1
    cnt_s.append(ds[s])
    cnt_t.append(dt[t])
print('Yes' if cnt_s == cnt_t else "No")

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
t = input()
csm = Counter(s).most_common()
ctm = Counter(t).most_common()
if len(csm)!=len(ctm):
    print('No')
else:
    for i in range(len(csm)):
        if csm[i][1]!=ctm[i][1]:
            print('No')
            break
        if i==len(csm)-1:
            print('Yes')

Submission status: Accepted

Solution code:
def get_char_set(word):
    char_index = {}
    for i, c in enumerate(word):
        if c not in char_index.keys():
            char_index[c] = []
        char_index[c].append(i)
    char_set = set()
    for char_index_list in char_index.values():
        char_set.add(tuple(char_index_list))
    return char_set

s = input()
t = input()

s_char_set = get_char_set(s)
t_char_set = get_char_set(t)
if s_char_set == t_char_set:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import defaultdict

S = list(input())
T = list(input())
ds = defaultdict(int)
dt = defaultdict(int)
cnt_s = []
cnt_t = []
for s, t in zip(S, T):
    ds[s] += 1
    dt[t] += 1
    cnt_s.append(ds[s])
    cnt_t.append(dt[t])
print('Yes' if cnt_s == cnt_t else "No")

Submission status: Accepted

Solution code:
from collections import Counter

sc=Counter(input())
tc=Counter(input())

for s,t in zip(sorted(sc.values()),sorted(tc.values())):
    if s!=t:
      print("No")
      break
else:
    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")
else:
  for s1,t1 in zip(sorted(sc.items(),key=lambda i: i[1]),sorted(tc.items(),key=lambda i: i[1])):
    if s1[1]!=t1[1]:
      print("No")
      break
  else:
    print("Yes")

Submission status: Accepted

Solution code:
from string import ascii_lowercase
s = input()
t = input()

begin = {c:None for c in ascii_lowercase}
end = {c:None for c in ascii_lowercase}

for idx in range(len(s)):
    sc = s[idx]
    tc = t[idx]
    if begin[sc] is not None and begin[sc] != tc:
        print('No')
        exit()
    if end[tc] is not None and end[tc] != sc:
        print('No')
        exit()
    begin[sc] = tc
    end[tc] = sc

print('Yes')

Submission status: Accepted

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
t = input()
a = [0]*26
b = [0]*26

for i in range(len(s)):
    x = ord(s[i])-ord('a')
    y = ord(t[i])-ord('a')
    a[x] += 1
    b[y] += 1

if sorted(a) == sorted(b):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
S = input()
T = input()
stot = dict()
ttos = dict()
for s, t in zip(S, T):
    stot.setdefault(s, set())
    stot[s].add(t)
    ttos.setdefault(t, set())
    ttos[t].add(s)

ans = 'Yes'
for k, l in stot.items():
    if len(l) > 1:
        ans = 'No'
        break

for k, l in ttos.items():
    if len(l) > 1:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
stot = dict()
sset = set()
tset = set()
for s, t in zip(S, T):
    if s in sset:
        dt = stot[s]
        if t != dt:
            print('No')
            break
    else:
        if not t in tset:
            stot[s] = t
            sset.add(s)
            tset.add(t)
        else:
            print('No')
            break
else:
    print('Yes')

Submission status: Accepted

Solution code:
S = input()
T = input()
length = len(S)
flg = 1
dic = {}
for i in range(length):
    data = S[i]
    if S[i] not in dic:  dic[S[i]] = T[i]
    else:
        if dic[S[i]] != T[i]:  flg = 0

dic = {}
for i in range(length):
    data = T[i]
    if T[i] not in dic:  
        dic[T[i]] = S[i]
    else:
        if dic[T[i]] != S[i]:  flg = 0
                
if flg:  print("Yes")
else:  print("No")

Submission status: Accepted

Solution code:
from collections import Counter

s = input()
t = input()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# from collections import Counter
s = list(str(input()))
t = list(str(input()))

dict_ = {}
for i in range(len(s)):
    if s[i] in dict_:
        dict_[s[i]].append(i)
    else:
        dict_[s[i]] = [i]
for key, value in dict_.items():
    a = set([])
    for i in value:
        a.add(t[i])
    # print(a)
    if len(set(a)) != 1:
        print("No")
        exit()

s, t = t, s
dict_ = {}
for i in range(len(s)):
    if s[i] in dict_:
        dict_[s[i]].append(i)
    else:
        dict_[s[i]] = [i]
for key, value in dict_.items():
    a = set([])
    for i in value:
        a.add(t[i])
    # print(a)
    if len(set(a)) != 1:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
s,t = raw_input(), raw_input()
def f(s,t):
	cc = {}
	cr = {}
	for u,v in zip(s,t):
		if u in cc:
			if cc[u] != v: return False
		if v in cr:
			if cr[v] != u: return False
		
		cc[u] = v
		cr[v] = u
	return True
print 'Yes' if f(s,t) else 'No'

Submission status: Accepted

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

s_t = {}
s = set()
t = set()
for i in range(len(S)):
    if S[i] not in s:
        if T[i] not in t:
            s.add(S[i])
            t.add(T[i])
            s_t[S[i]] = T[i]
        else:
            print("No")
            exit()
    else:
        if s_t[S[i]] != T[i]:
            print("No")
            exit()

print("Yes")

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
N = len(S)
dicS={}
dicT={}
for i in range(97,123,1):
    dicS[chr(i)] = []
    dicT[chr(i)] = []

for i in range(0,N,1):
    dicS[S[i]].append(i)
    dicT[T[i]].append(i)

for a2z in dicS:
    if len(dicS[a2z])>0:
        tmp = T[dicS[a2z][0]]
        for i in range(0,len(dicS[a2z]),1):
            if T[dicS[a2z][i]]!=tmp:
                print("No")
                exit()
    if len(dicT[a2z])>0:
        tmp = S[dicT[a2z][0]]
        for i in range(0,len(dicT[a2z]),1):
            if tmp != S[dicT[a2z][i]]:
                print("No")
                exit()

print("Yes")

Submission status: Accepted

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

exchange = [-1] * 26
alpha2num = lambda c: ord(c) - ord('a')
#print(alpha2num('y')) #==> 24

for i in range(len(S)):
    now_num = alpha2num(S[i])
    #print(now_num, exchange[now_num], alpha2num(T[i]))
    if exchange[now_num] == -1:
      exchange[now_num] = alpha2num(T[i])
    elif exchange[now_num] == alpha2num(T[i]):
      #print("yeee")
      continue
    else:
      print("No")
      quit()
  #print(exchange)    
  
exchange = sorted(exchange)
for i in range(1, 26):
  if exchange[i] == exchange[i - 1]:
    if exchange[i] != -1:
      print("No")
      quit()
  
print("Yes")

Submission status: Accepted

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

from collections import Counter
Counter_S=Counter(S)
Counter_T=Counter(T)
S_num=list(Counter_S.values())
T_num=list(Counter_T.values())

S_num.sort()
T_num.sort()

if S_num==T_num:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import defaultdict

s = input()
t = input()

in_deg = defaultdict(set)
out_deg = defaultdict(set)

for es, et in zip(s, t):
    out_deg[es].add(et)
    in_deg[et].add(es)

in_deg_mx = max(map(len, in_deg.values()))
out_deg_mx = max(map(len, out_deg.values()))

if in_deg_mx <= 1 and out_deg_mx <= 1:
    ans = "Yes"
else:
    ans = "No"

print(ans)

Submission status: Accepted

Solution code:
s=input()
t=input()
n=len(s)
d={}
for i in range(n):
    ss=s[i]
    tt=t[i]
    if ss in d and (ss,tt) not in d.items():
        print("No")
        exit()
    if tt in d.values() and (ss,tt) not in d.items():
        print("No")
        exit()
    if ss not in d:
        d[ss]=tt    
print("Yes")

Submission status: Accepted

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

s = input().rstrip()
t = input().rstrip()

scl = sorted(list(collections.Counter(s).values()))
tcl = sorted(list(collections.Counter(t).values()))

if scl == tcl:
    print('Yes')

else:
    print('No')

Submission status: Accepted

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

a = ord('a')
alf = []
for i in range(26):
     alf.append(chr(a))
     a += 1

SN = [[] for i in range(26)]
TN = [[] for i in range(26)]
for i in range(N):
    for j in range(26):
        if alf[j] == S[i]:
            SN[j].append(i)
        if alf[j] == T[i]:
            TN[j].append(i)
SN.sort()
TN.sort()
print('Yes' if SN == TN else 'No')

Submission status: Accepted

Solution code:
from collections import Counter

s = input().rstrip()
t = input().rstrip()

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

Submission status: Accepted

Solution code:
from collections import*
s,t=Counter(input()),Counter(input())
print("YNeos"[sorted(s.values())!=sorted(t.values())::2])

Submission status: Accepted

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

l = len(S)
S_lst = [None] * l
T_lst = [None] * l
S_dic = {}
T_dic = {}

s_cnt = 0
for i, s in enumerate(S):
    if s in S_dic:
        n = S_dic[s]
        S_lst[i] = n
    else:
        S_lst[i] = s_cnt
        S_dic[s] = s_cnt
        s_cnt += 1


t_cnt = 0
for i, t in enumerate(T):
    if t in T_dic:
        n = T_dic[t]
        T_lst[i] = n
    else:
        T_lst[i] = t_cnt
        T_dic[t] = t_cnt
        t_cnt += 1


if s_cnt != t_cnt:
    print('No')
    exit()

for i in range(l):
    if S_lst[i] != T_lst[i]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

d = {}

for i in range(len(S)):
    #print(S[i],"to",T[i])
    if S[i] not in d:
        if T[i] in d.values():
            print('No')
            break
        else:
            d[S[i]] = T[i]
    else:
        if d[S[i]] != T[i]:
            print('No')
            break
    #print(d)
else:
    print('Yes')