Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

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

|S| = |T|

S and T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T

Output

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

Sample Input 1

azzel
apple

Sample Output 1

Yes

azzel can be changed to apple, as follows:

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

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

Sample Input 2

chokudai
redcoder

Sample Output 2

No

No sequences of operation can change chokudai to redcoder.

Sample Input 3

abcdefghijklmnopqrstuvwxyz
ibyhqfrekavclxjstdwgpzmonu

Sample Output 3

Yes



Sample input:
azzel
apple


Sample output:
Yes

Submission status: Accepted

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

dict_1 = {}
dict_2 = {}

for i in range(len(S)):
    if dict_1.setdefault(S[i],T[i]) != T[i]:
        print("No")
        sys.exit()
    if dict_2.setdefault(T[i],S[i]) != S[i]:
        print("No")  
        sys.exit()  
print("Yes")

Submission status: Accepted

Solution code:
import sys
S = input()
T = input()
alphabet = [chr(i) for i in range(97, 97+26)]

dict_1 = {}
dict_2 = {}

for i in range(len(S)):
    if dict_1.setdefault(S[i],T[i]) != T[i]:
        print("No")
        sys.exit()
    if dict_2.setdefault(T[i],S[i]) != S[i]:
        print("No")  
        sys.exit()  
print("Yes")

Submission status: Accepted

Solution code:
from collections import Counter

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 = Counter(list(input()))
t = Counter(list(input()))
s = list(s.values())
t = list(t.values())
print("Yes" if sorted(s)==sorted(t) else "No")

Submission status: Accepted

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

memo_S = {}
memo_T = {}
answer = 'Yes'
for i in range(len(S)):
    if S[i] not in memo_S:
        memo_S[S[i]] = T[i]
    elif memo_S[S[i]] != T[i]:
        answer = 'No'
        break
    if T[i] not in memo_T:
        memo_T[T[i]] = S[i]
    elif memo_T[T[i]] != S[i]:
        answer = 'No'
        break
print(answer)

Submission status: Accepted

Solution code:
from collections import Counter

S,T = input(),input()
Sc, Tc = Counter(S),Counter(T)
print("Yes" if sorted(Sc.values()) == sorted(Tc.values()) else "No")

Submission status: Accepted

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

convert = dict()

bl = True
for s,t in zip(S,T):
  if s in convert and convert[s] != t:
    bl = False
    break
  convert[s] = t

# 変換先の重複チェック
after = convert.values()
if len(after) != len(set(after)):
  bl = False

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

Submission status: Accepted

Solution code:
from collections import Counter

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 = input()
t = input()

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

for x, y in zip(c1, c2):
    if x[1] != y[1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
S,T = input(),input()
str = "abcdefghijklmnopqrstuvwxyz"
dic,dic2 = [[] for _ in str],[[] for _ in str]
for i in range(len(S)):
    dic[str.index(S[i])].append(i)
for i in range(len(T)):
    dic2[str.index(T[i])].append(i)
dic.sort()
dic2.sort()
print("Yes" if dic == dic2 else "No")

Submission status: Accepted

Solution code:
s = str(input())
t = str(input())
d = dict()
f = dict()
for i in range(0,len(s)):
    if s[i] in d:
        if d[s[i]] != t[i]:
            print("No")
            break 
    else:
        d[s[i]] = t[i]
    if t[i] in f:
        if f[t[i]] != s[i]:
            print("No")
            break
    else:
        f[t[i]] = s[i]
else:
    print("Yes")

Submission status: Accepted

Solution code:
def pare_exist(ST_pare_lst, Si, Ti):
    if (Si, Ti) in ST_pare_lst:
        return True
    else:
        for Sj, Tj in ST_pare_lst:
            if (Sj == Si and Tj != Ti) or (Sj != Si and Tj == Ti):
                return False
        
        ST_pare_lst.append((Si, Ti))
        return None

def exchanging(S, T):
    ST_pare_lst = []
    length = len(S)

    for i in range(length):
        judge = pare_exist(ST_pare_lst, S[i], T[i])
        if judge is None:
            pass
        elif judge == True:
            pass
        else:   #   judge == False
            return False
    return True

def same_chr_contain(S, T):
    S_chr_lst = []
    T_chr_lst = []
    for i in range(len(S)):
        if not S[i] in S_chr_lst:
            S_chr_lst.append(S[i])
        if not T[i] in T_chr_lst:
            T_chr_lst.append(T[i])

    if len(S_chr_lst) == len(T_chr_lst):
        return True
    else:
        return False

S = input()
T = input()

ST_pare_lst = []
length = len(S)

if not same_chr_contain(S, T):
    print("No")
elif exchanging(S, T):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

S1=collections.Counter(S).most_common()
T1=collections.Counter(T).most_common()
if len(S1)!=len(T1):print('No');exit()
elif all(S1[i][1]==T1[i][1] for i in range(len(S1))):print('Yes')
else:print('No')

Submission status: Accepted

Solution code:
s=input()
t=input()
ss=list(set(s))
st=list(set(t))
s_cnt=[0]*len(ss)
t_cnt=[0]*len(st)
ans='No'
for i in range(len(ss)):
    s_cnt[i]=s.count(ss[i])
for i in range(len(st)):
    t_cnt[i]=t.count(st[i])
s_cnt.sort()
t_cnt.sort()
if  s_cnt==t_cnt:
    ans='Yes'
print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
sn=[0 for i in range(26)]
tn=[0 for i in range(26)]
for i in range(len(s)):
    sn[ord(s[i])-ord('a')]+=1
    tn[ord(t[i])-ord('a')]+=1
print('Yes' if sorted(sn) == sorted(tn) else 'No')

Submission status: Accepted

Solution code:
s = input()
t = input()
# snum = []
# tnum = []
# for c in range(ord('a'), ord('z') + 1):
#     snum.append([i for i, x in enumerate(s) if x == chr(c)])
# for c in range(ord('a'), ord('z') + 1):
#     tnum.append([i for i, x in enumerate(t) if x == chr(c)])
# snum.sort()
# tnum.sort()
# print('Yes' if snum == tnum else 'No')


sn=[0 for i in range(26)]
tn=[0 for i in range(26)]
for i in range(len(s)):
    sn[ord(s[i])-ord('a')]+=1
    tn[ord(t[i])-ord('a')]+=1
print('Yes' if sorted(sn) == sorted(tn) else 'No')

Submission status: Accepted

Solution code:
from collections import Counter
 
s = input()
t = input()
 
c1 = Counter(s).most_common()
c2 = Counter(t).most_common()
 
for i, j in zip(c1, c2):
  if i[1] != j[1]:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    t = input()

    sn = ''
    c_n = {}
    for i in s:
        if i not in c_n:
            c_n[i] = len(c_n)
        sn += str(c_n[i])
    
    tn = ''
    c_n = {}
    for i in t:
        if i not in c_n:
            c_n[i] = len(c_n)
        tn += str(c_n[i])


    if sn == tn:
        print('Yes')
    else:
        print('No')


solve()

Submission status: Accepted

Solution code:
from collections import Counter

s = input()
t = input()

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

for x, y in zip(c1, c2):
  if x[1] != y[1]:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
from sys import stdin

S = stdin.readline().rstrip()
T = stdin.readline().rstrip()
alphabet = 'abcdefghijklmnopqrstuvwxyz'
cnt = 0

for letter in alphabet:
    X = []
    Y = []
    for k in range(len(T)):
        if T[k] == letter:
            X.append(S[k])
            if len(X) > 1 and X[len(X) - 1] != X[len(X) - 2]:
                print('No')
                break
        if S[k] == letter:
            Y.append(T[k])
            if len(Y) > 1 and Y[len(Y) - 1] != Y[len(Y) - 2]:
                print('No')
                break
    if len(X) > 1 and X[len(X) - 1] != X[len(X) - 2]:
        break
    if len(Y) > 1 and Y[len(Y) - 1] != Y[len(Y) - 2]:
        break
    cnt += 1

if cnt == 26:
    print('Yes')

Submission status: Accepted

Solution code:
Sp = list(input())
Tp = list(input())
S = [ord(Sp[i])-ord('a') for i in range(len(Sp))]
T = [ord(Tp[i])-ord('a') for i in range(len(Tp))]
lis = [-1]*26
lit = [-1]*26
ans = True
for i in range(len(S)):
    if lis[S[i]] == -1:
        lis[S[i]] = T[i]
    else:
        if lis[S[i]] != T[i]:
            ans = False
            break
for i in range(len(T)):    
    if lit[T[i]] == -1:
        lit[T[i]] = S[i]
    else:
        if lit[T[i]] != S[i]:
            ans = False
            break
if ans:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
s_element = list(set(S))
t_element = list(set(T))
s_count = [0]*(len(s_element))
t_count = [0]*(len(t_element))
for i in range(len(s_element)):
    s_count[i] = S.count(s_element[i])
for i in range(len(t_element)):
    t_count[i] = T.count(t_element[i])
x = sorted(s_count)
y = sorted(t_count)
print("Yes" if x==y else "No")

Submission status: Accepted

Solution code:
from sys import stdin
from collections import OrderedDict
reference_data = OrderedDict()

S = stdin.readline().rstrip()
T = stdin.readline().rstrip()
s = OrderedDict()
t = OrderedDict()
for a,b in zip(S,T):
    s[a] = set()
    t[b] = set()
for ind,i in enumerate(S):
    s[i].add(ind)
for ind,j in enumerate(T):
    t[j].add(ind)
if list(s.values()) == list(t.values()):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#c
import copy

S = input()
T = input()

def change(string, c1, c2):
    ret = []
    for s in string:
        if s is c1:
            ret.append(c2)
        elif s is c2:
            ret.append(c1)
        else:
            ret.append(s)
    return ret

S_ = copy.deepcopy(S)
history = []

while True:
    if S_ in history:
        print('No')
        exit()
    history.append(S_)
    for i, s in enumerate(S_):
        if s is not T[i]:
            S_ = copy.deepcopy(''.join(change(S_, s, T[i])))
            break
        if i == len(S_)-1:
            print('Yes')
            exit()

Submission status: Accepted

Solution code:
import copy

S = input()
T = input()

def change(string, c1, c2):
    ret = []
    for s in string:
        if s is c1:
            ret.append(c2)
        elif s is c2:
            ret.append(c1)
        else:
            ret.append(s)
    return ret

S_ = copy.deepcopy(S)
history = []

while True:
    if S_ in history:
        print('No')
        exit()
    for i, s in enumerate(S_):
        history.append(S_)
        if s is not T[i]:
            S_ = copy.deepcopy(''.join(change(S_, s, T[i])))
            break
        if i == len(S_)-1:
            print('Yes')
            exit()

Submission status: Accepted

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

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

def solve(S: str, T: str):

    stdic = {}
    for s,t in zip(S,T):
        if s not in stdic:
            stdic[s] = t
        else:
            if stdic[s] != t:
                print(NO)
                return

    checkv = []
    for k,v in stdic.items():
        checkv.append(v)


    if len(checkv) == len(set(checkv)):
        print(YES)
    else:
        print(NO)

    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S, T = open(0).read().split()
m1, m2 = {}, {}
for s, t in zip(S, T):
    if s in m1:
        m1[s].add(t)
    else:
        m1[s] = set(t)
    if t in m2:
        m2[t].add(s)
    else:
        m2[t] = set(s)
for v1, v2 in zip(m1.values(), m2.values()):
    if len(v1) != 1 or len(v2) != 1:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
 
test = [-1] * 26
test2 = [-1] * 26

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

    if (test[a] != -1) or test2[b] != -1:
        if test[a] != b or test2[b] != a:
           print("No")
           exit()

    else:
        test[a] = b
        test2[b] = a


print("Yes")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 19 14:58:59 2019

@author: Yamazaki Kenichi
"""

S = input()
T = input()
N = len(S)
flg = True
x ={}
for i in range(N):
    try:
        if x[S[i]] == T[i]:
            continue
        else:
            flg = False
    except:
        x[S[i]] = T[i]
x ={}
for i in range(N):
    try:
        if x[T[i]] == S[i]:
            continue
        else:
            flg = False
    except:
        x[T[i]] = S[i]
if flg:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - String Transformation
https://atcoder.jp/contests/abc110/tasks/abc110_c

"""
import sys

def sovle(S, T):
    st_d = dict()
    ts_d = dict()
    for s, t in zip(S, T):
        if s not in st_d:
            st_d[s] = t
        else:
            if st_d[s] != t:
                return 'No'
        if t not in ts_d:
            ts_d[t] = s
        else:
            if ts_d[t] != s:
                return 'No'
    return 'Yes'


def main(args):
    S = input()
    T = input()
    ans = sovle(S, T)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
s1 = input().strip()
s2 = input().strip()
F = True
d = {}
s = {}
for i in range(len(s1)):
  if s2[i] not in s:
     s[s2[i]] = s1[i]
  elif s[s2[i]] != s1[i]:
      F = False
      break
  if s1[i] not in d:
      d[s1[i]] = s2[i]
  elif d[s1[i]] != s2[i]:
       F = False
       break
if F:
   print('Yes')
else:
   print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May 17 00:23:37 2019

@author: avina
"""

s1 = input().strip()
s2 = input().strip()
F = True
d = {}
s = {}
for i in range(len(s1)):
  if s2[i] not in s:
     s[s2[i]] = s1[i]
  elif s[s2[i]] != s1[i]:
      F = False
      break
for i in range(len(s1)):
  if s1[i] not in d:
     d[s1[i]] = s2[i]
  elif d[s1[i]] != s2[i]:
      F = False
      break

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May 17 12:54:56 2019

@author: avina
"""

S = input()
T = input()
S_map = {}
T_map = {}
l = len(S)
k = 0
S_cnt = 0
T_cnt = 0
for i in range(l):
	s,t = S[i], T[i]
	if s in S_map:
		s_id = S_map[s]
	else:
		s_id = S_cnt
		S_map[s] = S_cnt
		S_cnt += 1
	if t in T_map:
		t_id = T_map[t]
	else:
		t_id = T_cnt
		T_map[t] = T_cnt
		T_cnt += 1
	if s_id != t_id:
		print("No");k+=1
		break
if k == 0:
    print("Yes")

Submission status: Accepted

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


def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]


alphabet = [0] * 26
alphabet2 = [0] * 26

for i in range(97, 97+26):
    alphabet[i-97] = my_index_multi(S, chr(i))
    alphabet2[i-97] = my_index_multi(T, chr(i))

ans = 'Yes'
for i in range(26):
    if not alphabet[i]:
        continue
    else:
        if not alphabet[i] in alphabet2:
            ans = 'No'
            break

print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
s_list = [-1 for i in range(26)]
t_list = [-1 for i in range(26)]
for i in range(len(s)):
    if s_list[ord(s[i]) - ord("a")] == -1:
        s_list[ord(s[i]) - ord("a")] = ord(t[i])
    else:
        if s_list[ord(s[i]) - ord("a")] != ord(t[i]):
            print("No")
            exit()
    if t_list[ord(t[i]) - ord("a")] == -1:
        t_list[ord(t[i]) - ord("a")] = ord(s[i])
    else:
        if t_list[ord(t[i]) - ord("a")] != ord(s[i]):
            print("No")
            exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
t = input()
n = len(s)
p = [-1] * 26
q = [-1] * 26
b = True
for i in range(n):
    v = ord(s[i]) - ord('a')
    w = ord(t[i]) - ord('a')
    if p[v] != w:
        if p[v] == -1:p[v] = w
        else :b = False
    if q[w] != v:
        if q[w] == -1:q[w] = v
        else :b = False

if b == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
S = input()
T = input()
st = {}
ts = {}
for s, t in zip(S, T):
  if st.get(s, t) != t:
    print('No')
    break
  else:
    st[s] = t
  if ts.get(t, s) != s:
    print('No')
    break
  else:
    ts[t] = s
else:
  print('Yes')

Submission status: Accepted

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

a = "abcdefghijklmnopqrstuvwxyz"
b = [0]*26
flag = 0

for i in range(len(s)):
    tmp = a.index(s[i])
    if b[tmp] == 0:
        b[tmp] = t[i]
        if b.count(t[i]) > 1:
            flag = 1
            break
    elif b[tmp] != t[i] :
        flag = 1
        break

        
print("Yes" if flag == 0 else "No")

Submission status: Accepted

Solution code:
A = input()
B = input()

dA = [-1]*26
dB = [-1]*26
cA = 0
cB = 0
pA = []
pB = []

le = len(A)

for i in range(le):
  v = ord(A[i])-ord("a")
  if ( dA[v]==-1 ):
    dA[v]=cA
    pA.append(cA)
    cA+=1
  else:
    pA.append( dA[v] )

for i in range(le):
  v = ord(B[i])-ord("a")
  if ( dB[v]==-1 ):
    dB[v]=cB
    pB.append(cB)
    cB+=1
  else:
    pB.append( dB[v] )

s = le
for i in range(le):
  if (pA[i]==pB[i]):
    s-=1
if (s==0):
  print ("Yes")
else:
  print ("No")

Submission status: Accepted

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

X = {}
for i in range(N):
  if T[i] not in X.keys():
    X[T[i]] = []
  X[T[i]].append(S[i])
Y = {}
for i in range(N):
  if S[i] not in Y.keys():
    Y[S[i]] = []
  Y[S[i]].append(T[i])

for i,j in X.items():
  if len(set(j)) >= 2:
    print('No')
    exit()
for i,j in Y.items():
  if len(set(j)) >= 2:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
A = input()
B = input()

flag = True
if len(A) != len(B):
  flag = False 

pair_dict = dict()
reverse_dict = dict()
for i in range(len(A)):
  if A[i] not in pair_dict:
    pair_dict[A[i]] = B[i]
  elif pair_dict[A[i]] != B[i]:
    flag = False
    break
  if B[i] not in reverse_dict:
    reverse_dict[B[i]] = A[i]
  elif reverse_dict[B[i]] != A[i]:
    flag = False
    break
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

s_dic = {}
t_dic = {}
s_cnt = 0
t_cnt = 0
s_mod = ''
t_mod = ''
for i in range(0, len(s)):
  if s[i] not in s_dic:
    s_dic[s[i]] = s_cnt
    s_cnt += 1

  s_mod += str(s_dic[s[i]])
  
  if t[i] not in t_dic:
    t_dic[t[i]] = t_cnt
    t_cnt += 1
  
  t_mod += str(t_dic[t[i]])
  
if s_mod == t_mod:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

r1 = [-1] * 26
r2 = [-1] * 26


def char2index(char):
    return ord(char) - 97


sn = [char2index(si) for si in s]
tn = [char2index(ti) for ti in t]

flg = True
for si, ti in zip(sn, tn):
    if r1[si] >= 0:
        if r1[si] != ti:
            flg = False
            break
    else:
        r1[si] = ti
    if r2[ti] >= 0:
        if r2[ti] != si:
            flg = False
            break
    else:
        r2[ti] = si

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

Submission status: Accepted

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

mapping = {}
for s, t in zip(S, T):
    if s not in mapping and t not in mapping.values():
        mapping[s] = t
    elif s not in mapping and t in mapping.values():
        print('No')
        break
    elif mapping[s] != t:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

def main(S, T):
    seen = {}

    for i in range(len(S)):
        if S[i] not in seen:
            seen[S[i]] = T[i]
        else:
            if seen[S[i]] != T[i]:
                return 0
    return 1

ans = main(s, t)*main(t, s)
if ans == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys

s = input().strip()
t = input().strip()

d = dict()
for i, sc in enumerate(s):
    tc = t[i]

    if sc in d:
        if d[sc] == tc:
            continue
        else:
            print('No')
            sys.exit(0)

    d[sc] = tc

vs = list(d.values())
for v in vs:
    if vs.count(v) > 1:
        print('No')
        sys.exit(0)

print('Yes')

Submission status: Accepted

Solution code:
s = input()
t = input()
a_z = 'abcdefghijklmnopqrstuvwxyz'
D1 = dict(zip([c for c in a_z],[-1 for _ in range(len(a_z))]))
D2 = dict(zip([c for c in a_z],[-1 for _ in range(len(a_z))]))
for x, y in zip(s, t):
    if D1[x] == -1:
        D1[x] = y
    else:
        if D1[x] != y:
            print('No')
            exit()
    if D2[y] == -1:
        D2[y] = x
    else:
        if D2[y] != x:
            print('No')
            exit()
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
S = list(input())
T = list(input())
#print (S)

dic1 = dict()
dic2 = dict()
for i in range(len(S)):
    if not S[i] in dic1.keys():
        dic1[S[i]] = 1
    else:
        dic1[S[i]] += 1
    if not T[i] in dic2.keys():
        dic2[T[i]] = 1
    else:
        dic2[T[i]] += 1
#print(dic1)

dic1 = sorted(dic1.items(), key = lambda x:x[1])
dic2 = sorted(dic2.items(), key = lambda x:x[1])

for j in range(len(dic1)):
    if not dic1[j][1] == dic2[j][1]:
        print ('No')
        sys.exit()
print ('Yes')

Submission status: Accepted

Solution code:
s,t=input(),input()
s_set,t_set,st_set=set(),set(),set()
for i,j in zip(s,t):
    if i not in s_set and j not in t_set:
        s_set.add(i)
        t_set.add(j)
    elif (i,j) not in st_set:
        print("No")
        break
    st_set.add((i,j))
else:
    print("Yes")

Submission status: Accepted

Solution code:
s=input()
t=input()
S={}
T={}
for i in range(len(s)):
    if s[i] in S.keys() and t[i] in T.keys():
        if S[s[i]]!=T[t[i]]:
            print("No")
            exit()
        else:
            S[s[i]]+=1
            T[t[i]]+=1
    elif s[i] not in S.keys() and t[i] not in T.keys():
        S[s[i]]=1
        T[t[i]]=1
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

table = [[0 for i in range(26)] for j in range(26)]
for i in range(len(s)):
  table[ord(t[i])-ord('a')][ord(s[i])-ord('a')] += 1
for t_row in table:
  counter = 0
  for v in t_row:
    if v != 0:
      counter += 1
  if counter >= 2:
    break
else:
  for i in range(26):
    counter = 0
    for j in range(26):
      if table[j][i] != 0:
        counter += 1
    if counter >= 2:
      break
  else:
    print('Yes')
    exit(0)
print('No')

Submission status: Accepted

Solution code:
S = [c for c in input()]
T = [c for c in input()]
ST = [[s,t] for s,t in zip(S,T)]
S_dict = {}
T_dict = {}
for s,t in ST:
    if s not in S_dict:
        S_dict[s] = [t]
    elif t not in S_dict[s]:
        S_dict[s].append(t)
    if t not in T_dict:
        T_dict[t] = [s]
    elif s not in T_dict[t]:
        T_dict[t].append(s)

S_tmp = max([len(x) for x in S_dict.values()])
T_tmp = max([len(x) for x in T_dict.values()])
tmp = max(S_tmp, T_tmp)
flag = True if tmp < 2 else False
print('Yes' if flag else 'No')
# print(S_dict)

Submission status: Accepted

Solution code:
from collections import defaultdict

S=input()
T=input()

ds={}
dt={}
for i in range(len(S)):
  if S[i] not in ds:
    ds[S[i]]=T[i]
  elif ds[S[i]]!=T[i]:
    print('No')
    exit()
  if T[i] not in dt:
    dt[T[i]]=S[i]
  elif dt[T[i]]!=S[i]:
    print('No')
    exit()
      
print('Yes')

Submission status: Accepted

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

char_map = {}
char_map_t = {}

result = 'Yes'

for s, t in zip(S, T):
    if s in char_map:
        if t == char_map[s]:
            continue
        else:
            result = 'No'
            break
    else:
        char_map[s] = t

    if t in char_map_t:
        if s == char_map_t[t]:
            continue
        else:
            result = 'No'
            break
    else:
        char_map_t[t] = s

print(result)

Submission status: Accepted

Solution code:
s=input()
t=input()
arr1=[0]*26
arr2=[0]*26
check='abcdefghijklmnopqrstuvwxyz'
for i in range(26):
  arr1[i]=s.count(check[i])
  arr2[i]=t.count(check[i])
arr1=sorted(arr1)
arr2=sorted(arr2)
for i in range(26):
  if arr1[i]!=arr2[i]:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def parse_str(x):
    ret = {}
    for i, c in enumerate(x):
        ret.setdefault(c, [])
        ret[c].append(i)
    return ret


def main():
    s = input()
    t = input()

    s_parse = parse_str(s)
    t_parse = parse_str(t)

    spos = [pos for pos in s_parse.values()]
    spos.sort()
    tpos = [pos for pos in t_parse.values()]
    tpos.sort()

    if spos == tpos:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

s = input()
t = input()
ds = defaultdict(str)
dt = defaultdict(str)

ans = "Yes"
for c1, c2 in zip(s, t):
    if c1 not in ds:
        ds[c1] = c2
    else:
        if ds[c1] != c2:
            ans = "No"
    
    if c2 not in dt:
        dt[c2] = c1
    else:
        if dt[c2] != c1:
            ans = "No"
print(ans)

Submission status: Accepted

Solution code:
S, T=input(), input()
src, trg = {}, {}
for i in range(len(S)):
    s, t = S[i], T[i]
    if (s in src and src[s] != t) or (t in trg and trg[t] != s):
        print("No")
        exit()
    src[s] = t
    trg[t] = s
print("Yes")

Submission status: Accepted

Solution code:
#3
s = str(input())
t = str(input())
memo = {}
ifadd = False
ifsamedest = False
destlist = set()
for i in range(len(s)):
    sor = s[i]
    des = t[i]
    if sor not in memo:
        memo[sor] = des
        if des in destlist:
            ifsamedest = True
        destlist.add(des)
    else:
        if memo[sor]!=des:
            ifadd = True

#同じ文字から複数の行き先はアウト
#異なる文字から同じ行き先もアウト
#交換関係になっていなければアウト


ans = "Yes"
visited = set()
if ifadd == True:
    ans = "No"
if ifsamedest == True:
    ans = "No"
else:
    for sta in memo:
        if sta not in visited:
            visited.add(sta)
            gol = memo[sta]
            fsta = sta
            while(gol!=sta):
                if gol not in memo:
                    gol = sta
                else:
                    sta,gol = gol,memo[gol]
                    visited.add(sta)
                    if gol == fsta:
                        gol = sta
                        
print(ans)

Submission status: Accepted

Solution code:
s1 = input()
s2 = input()
di1 = {} #s1 → s2 の対応表
di2 = {} #s2 → s1 の対応表

ans = "Yes"
for c1,c2 in zip(s1,s2):
    if c1 not in di1:
        di1[c1] = c2
    else:
        if di1[c1] != c2:
            ans = "No"

    if c2 not in di2:
        di2[c2] = c1
    else:
        if di2[c2] != c1:
            ans = "No"

print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
from collections import defaultdict
dic1 = defaultdict(set)
dic2 = defaultdict(set)
for i in range(len(s)):
    dic1[s[i]].add(t[i])
    dic2[t[i]].add(s[i])
f = True
for c in dic1.keys():
    if len(dic1[c]) >= 2:
        f = False
        break
for c in dic2.keys():
    if len(dic2[c]) >= 2:
        f = False
        break
print("Yes" if f else "No")