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

stdin = sys.stdin

mod = 1000000007
inf = 1 << 60

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

from collections import OrderedDict

s = ns()
t = ns()
n = len(s)

ds = OrderedDict.fromkeys(s, 0)
dt = OrderedDict.fromkeys(t, 0)

for i in range(n):
    ds[s[i]] += 1

for i in range(n):
    dt[t[i]] += 1

flag = True
for i, j in zip(ds.values(), dt.values()):
    if i != j:
        flag = False

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

Submission status: Accepted

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

ok = True

RS = {}
RT = {}

for i in range(len(S)):
    s = S[i]
    t = T[i]
    if s in RS:
        if RS[s] != t:
            ok = False
    if t in RT:
        if RT[t] != s:
            ok = False
    RS[s] = t
    RT[t] = s
if ok:
    print('Yes')
else:
    print("No")

Submission status: Accepted

Solution code:
s = input()
t = input()
d_s = dict()
d_t = dict()
for i in range(len(s)):
  if not s[i] in d_s:
    d_s[s[i]] = t[i]
  elif d_s[s[i]] != t[i]:
    print('No')
    exit()
  if not t[i] in d_t:
    d_t[t[i]] = s[i]
  elif d_t[t[i]] != s[i]:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
S=input()
T=input()
ng = 0
ds = {}
dt = {}
for i in range(len(S)):
    if S[i] in ds:
        if ds[S[i]] != T[i]:
            ng = 1
            break;
    else:
        ds[S[i]] = T[i]
    if T[i] in dt:
        if dt[T[i]] != S[i]:
            ng = 1
            break;
    else:
        dt[T[i]] = S[i]

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

S = cin.string()
T = cin.string()

def solve():
    X = _collections.defaultdict(lambda:"-1")
    Y = _collections.defaultdict(lambda:"-1")

    for i in range(len(S)):
        s = S[i]
        t = T[i]
        if X[s] != "-1" or Y[t] != "-1":
            if X[s] != t or Y[t] != s:
                return "No"
        X[s] = t
        Y[t] = s

    return "Yes"
print(solve())

Submission status: Accepted

Solution code:
import sys

use_clipboard=True
bbn=1000000007
	
#+++++

def check(sc,tc):
	sc.sort()
	tc.sort()
	for u,v in zip(sc,tc):
		if len(u)!=len(v):
			return False
		for i,j in zip(u,v)	:
			if i!=j:
				return False
	return True
		
						
def main():
	s = input()
	t = input()
	c2i=lambda c : ord(c)-ord('a')
	sc=[[] for _ in range(26)]
	tc=[[] for _ in range(26)]
	
	for i,c in enumerate(s):
		#pa(c2i(c))
		sc[c2i(c)].append(i)
		
	for i,c in enumerate(t):
		tc[c2i(c)].append(i)
		
		
	ret = 'Yes' if check(sc,tc) else 'No'
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)


class input_clipboard:
	def __init__(self,s):
		self.input_l=s.splitlines()
		self.ii=0
		
	def input(self):
		ret = self.input_l[self.ii]
		self.ii+=1
		return ret


if __name__ == "__main__":
	if sys.platform =='ios':
		if use_clipboard:
			import clipboard
			input_text=clipboard.get()
			ic=input_clipboard(input_text)
			input = lambda : ic.input()
		else:
			sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
s=list(input())
t=list(input())
s_r=["*"]
t_r=["*"]
s_ans=[]
t_ans=[]
for c in s:
  if c in s_r:
    s_ans.append(s_r.index(c))
  else:
    s_r.append(c)
    s_ans.append(len(s_r)-1)
for c in t:
  if c in t_r:
    t_ans.append(t_r.index(c))
  else:
    t_r.append(c)
    t_ans.append(len(t_r)-1)
print("Yes" if t_ans==s_ans else "No")

Submission status: Accepted

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

dic_s = dict()
dic_t = dict()

for ind, s in enumerate(S):
    if dic_s.get(s) is None:
        dic_s[s] = {ind}
    else:
        dic_s[s].add(ind)
for ind, t in enumerate(T):
    if dic_t.get(t) is None:
        dic_t[t] = {ind}
    else:
        dic_t[t].add(ind)

ans = 1
for s_key in dic_s:
    for t_key in dic_t:
        if dic_s[s_key] == dic_t[t_key]:
            break
    else:
        ans = 0
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    S=list(input())
    T=list(input())
    d_S,d_T={},{}
    c=0
    for i,(s,t) in enumerate(zip(S,T)):
        if s in d_S:
            tmp_S=d_S[s]
        else:
            d_S[s]=c
            tmp_S=d_S[s]
        if t in d_T:
            tmp_T=d_T[t]
        else:
            d_T[t]=c
            tmp_T=d_T[t]
            c+=1
        if tmp_S!=tmp_T:
            print('No')
            exit()
    print('Yes')
        

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections

cntS = collections.Counter(input())
cntT = collections.Counter(input())

if sorted(cntS.values()) == sorted(cntT.values()):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

d1 = {}
d2 = {}
ans = "Yes"
for s, t in zip(S, T):
    if s in d1:
        if d1[s] != t:
            ans = "No"
            break
    else:
        d1[s] = t
    if t in d2:
        if d2[t] != s:
            ans = "No"
            break
    else:
        d2[t] = s
print(ans)

Submission status: Accepted

Solution code:
def solve():
    S = input()
    T = input()
    
    s_counter = sorted([S.count(chr(i)) for i in range(ord('a'), ord('z') + 1)])
    t_counter = sorted([T.count(chr(i)) for i in range(ord('a'), ord('z') + 1)])
    if s_counter == t_counter:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
R1 = [-1]*26
R2 = [-1]*26
ans = "Yes"

for i in range(len(S)):
    s = ord(S[i])
    t = ord(T[i])
    if R1[s-97] >= 0:
        if R1[s-97] != t:
            ans = "No"
            break
    else:
        R1[s-97] = t
    if R2[t-97] >= 0:
        if R2[t-97] != s:
            ans = "No"
            break
    else:
        R2[t-97] = s

print(ans)

Submission status: Accepted

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

s = collections.Counter(S)
t = collections.Counter(T)

ss = s.most_common()
tt = t.most_common()

if len(ss) != len(tt):
    print("No")
    exit()

for i in range(len(ss)):
    if ss[i][1] != tt[i][1]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

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

a = [0] * 26
b = [0] * 26
for i, j in zip(s, t):
    if a[ord(i) - 97] != 0 or b[ord(j) - 97] != 0:
        if a[ord(i) - 97] != j or b[ord(j) - 97] != i:
            print("No")
            exit()
    a[ord(i) - 97] = j
    b[ord(j) - 97] = i

print("Yes")

Submission status: Accepted

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

a = [[0 for _ in range(26)] for _ in range(26)]
b = [[0 for _ in range(26)] for _ in range(26)]
for i, j in zip(s, t):
    a[ord(i) - 97][ord(j) - 97] = 1
    b[ord(j) - 97][ord(i) - 97] = 1

for i, j in zip(a, b):
    if sum(i) >= 2 or sum(j) >= 2:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
from collections import defaultdict
S = input()
T = input()
d = defaultdict(set)
for s, t in zip(S, T):
    d[s].add(t)

for v in d.values():
    if len(v) != 1:
        print("No")
        exit()

chars = set()
for k, v in d.items():
    for x in v:
        if x in chars:
            print("No")
            exit()
        chars.add(x)
print("Yes")

Submission status: Accepted

Solution code:
def main():
    S = input()
    T = 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')
                return
        else:
            start[a] = b
            goal[b] = a
    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
t=input()
n=len(s)
A='abcdefghijklmnopqrstuvwxyz'
i=0
while A:
    if s==t:
        print('Yes')
        exit()
    if i==n:
        print('No')
        exit()
    if s[i]==t[i]:
        if s[i] in A:
            A=A.replace(s[i],'')
    else:
        if s[i] in A and t[i] in A:
            if t[i] in s:
                A=A.replace(t[i],'')
                s=s.replace(s[i],'X').replace(t[i],s[i]).replace('X',t[i])
            else:
                A=A.replace(t[i],'')
                s=s.replace(s[i],t[i])
        else:
            print('No')
            exit()
    i+=1

Submission status: Accepted

Solution code:
s=input()
t=input()
seen=set()
for i in range(len(s)):
  if s[i] not in seen:
    for j in range(i,len(t)):
      if s[i]==s[j]:
        if t[i]!=t[j]:
          print("No")
          exit(0)
      else:
        if t[i]==t[j]:
          print("No")
          exit(0)
    seen.add(s[i])
else:
  print("Yes")

Submission status: Accepted

Solution code:
from collections import Counter

S = input()
T = input()

s = list(Counter(S).values())
t = list(Counter(T).values())
s.sort()
t.sort()
if len(s) != len(t) or s != t:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
S = input()
T = input()
Sdictionary = {}
Tdictionary = {}
ans = "Yes"
for i in range(len(S)):
    if T[i] in Tdictionary:
        if Tdictionary[T[i]] == S[i]:
            continue
        else:
            ans = "No"
    else:
        Tdictionary[T[i]] = S[i]
    if S[i] in Sdictionary:
        if Sdictionary[S[i]] == T[i]:
            continue
        else:
            ans = "No"
    else:
        Sdictionary[S[i]] = T[i]


print(ans)

Submission status: Accepted

Solution code:
#ABC110C
import sys
s=input();t=input()
start=[-1]*26
goal=[-1]*26
for i in range(len(s)):
    a=int(ord(s[i])-97)
    b=int(ord(t[i])-97)
    if start[a]!=-1 or goal[b]!=-1:
        if start[a]!=b or goal[b]!=a:
            print("No")
            sys.exit()
    else:
        start[a]=b
        goal[b]=a
print("Yes")

Submission status: Accepted

Solution code:
s=input()
t=input()
st={}
ts={}

for x,y in zip(s,t):
  if x not in st:
    st[x]=y
  else:
    if st[x]!=y:
      print("No")
      exit()
  if y not in ts:
    ts[y]=x
  else:
    if ts[y]!=x:
      print("No")
      exit()
print("Yes")

Submission status: Accepted

Solution code:
from collections import Counter

s = input()
t = input()

count_s = Counter()
count_t = Counter()

for i in s:
    count_t[i] += 1

for j in t:
    count_s[j] += 1


s_list = sorted(list(dict(count_s).values()))
t_list = sorted(list(dict(count_t).values()))

if s_list == t_list:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

s_to_t = [None for _ in range(ord("z")-ord("a")+1)]
t_to_s = [None for _ in range(ord("z")-ord("a")+1)]

a = ord("a")
for s, t in zip(S, T):
    s = ord(s) - a
    t = ord(t) - a

    if s_to_t[s] is None:
        s_to_t[s] = t
    else:
        if s_to_t[s] != t:
            print("No")
            exit()
    
    if t_to_s[t] is None:
        t_to_s[t] = s
    else:
        if t_to_s[t] != s:
            print("No")
            exit()

print("Yes")

Submission status: Accepted

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



def main():
    S = input().strip()
    T = input().strip()

    c1 = Counter()
    c2 = Counter()

    for i in range(len(S)):
        c1[S[i] + T[i]] += 1
        c2[T[i] + S[i]] += 1

    for i in list("abcdefghijklmnopqrstuvwxyz"):
        count1 = 0
        count2 = 0
        for j in list("abcdefghijklmnopqrstuvwxyz"):
            if c1[i + j] > 0:
                count1 += 1
            if c2[i + j] > 0:
                count2 += 1
        if count1 > 1 or count2 > 1:
            print("No")
            break
    else:
        print("Yes")




if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = "Yes"
_dict = {}

for i in range(len(s)):
    if s[i] not in _dict:
        _dict[s[i]]=t[i]
    elif s[i] in _dict:
        if t[i] != _dict[s[i]]:
            ans="No"
            break

_dict = {}
for i in range(len(s)):
    if t[i] not in _dict:
        _dict[t[i]]=s[i]
    elif t[i] in _dict:
        if s[i] != _dict[t[i]]:
            ans="No"
            break
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

s, t = sys.stdin.read().split()
n = len(s)

def main():
    correspondence = defaultdict(str)
    for i in range(n):
        if not correspondence[s[i]]:
            correspondence[s[i]] = t[i]
        else:
            if correspondence[s[i]] != t[i]:
                return 'No'

    v = correspondence.values()
    return 'Yes' if len(v) == len(set(v)) else 'No'
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
alp = "abcdefghijklmnopqrstuvwxyz"
d = {s: None for s in alp}
e = {s: None for s in alp}
for s, t in zip(S, T):
    if d[t] is None:
        d[t] = s
    elif d[t] != s:
        print("No")
        exit()
    if e[s] is None:
        e[s] = t
    elif e[s] != t:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:

S = input()
T = input()
from collections import defaultdict

dictS = defaultdict(str)
dictT = defaultdict(str)

for i in range(len(S)):
  
  if dictT[T[i]] and dictT[T[i]] != S[i]:
    print("No")
    exit()
  
  if dictS[S[i]] and dictS[S[i]] != T[i]:
    print("No")
    exit()


  dictS[S[i]] = T[i]
  dictT[T[i]] = S[i]

print("Yes")

Submission status: Accepted

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

ans = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
res = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
for a,b in zip(s,t):
    ans[b].append(a)
    res[a].append(b)

aa = [0 for v in ans.values() if len(set(v)) > 1]
bb = [0 for v in res.values() if len(set(v)) > 1]

if len(aa) == 0 and len(bb) == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

ans = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
res = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
cnt = 0
for a,b in zip(s,t):
    ans[b].append(a)
    res[a].append(b)
    # elif ans[a] != a and ans[ans[a]] != ans[b]:
    #     print(a, b, '0', a, b, ans[a],  ans[b], cnt)
    #     print('No')
    #     break
    cnt += 1

aa = [0 for v in ans.values() if len(set(v)) > 1]
bb = [0 for v in res.values() if len(set(v)) > 1]

if len(aa) == 0 and len(bb) == 0:
    print('Yes')
else:
    print('No')
# print(ans)

Submission status: Accepted

Solution code:
S = input().strip()
T = input().strip()
F = {}
flag = 0
for i in range(len(S)):
    a = S[i]
    b = T[i]
    if a not in F:
        F[a] = b
    if F[a] != b:
        flag = 1
        break
    for c in F:
        if c!=a and F[c]==b:
            flag = 1
            break
if flag==1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
s=input()
t=input()
d={}
l=[]
for i in range(len(s)):
  if s[i] in d and d[s[i]]!=t[i]:
    print('No') 
    exit()
  d[s[i]]=t[i]
if len(d.values())!=len(set(d.values())):
  print('No')
  exit()
print('Yes')

Submission status: Accepted

Solution code:
from collections import defaultdict

s=input()
t=input()

n=len(s)

ss=defaultdict(list)
tt=defaultdict(list)

for i in range(n):
  ss[s[i]].append(i)
  tt[t[i]].append(i)

  
sss=[]
ttt=[]
for k,v in ss.items():
  sss.append(v)
for k,v in tt.items():
  ttt.append(v)

sss.sort()
ttt.sort()


ans="No"
if sss==ttt:
  ans="Yes"
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

from collections import Counter
cs = Counter(S)
ct = Counter(T)

anss = ['Yes','No']
ans = 0
if len(cs.keys()) != len(ct.keys()): ans = 1
else:
    As = sorted(cs.values())
    At = sorted(ct.values())
    for i in range(len(cs.keys())):
        if As[i] != At[i]:
            ans = 1
            break
print(anss[ans])

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

S, T = [sys.stdin.buffer.readline().decode().rstrip() for _ in range(2)]

def conv(s):
    cnt = 0
    num = {}
    ret = []
    for c in s:
        if c not in num:
            num[c] = cnt
            cnt += 1
        ret.append(num[c])
    return ret
ok = conv(S) == conv(T)
if ok:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter
s=Counter(list(input()))
t=Counter(list(input()))
s, t=list(s.values()),list(t.values())
print("Yes" if sorted(s)==sorted(t) else "No")

Submission status: Accepted

Solution code:
def main():
    S = input()
    T = input()
    d = dict()
    flg = True
    for s, t in zip(S, T):
        # 同アルファベット、違アルファベット変換チェック
        if s in d and d[s] != t:
            flg = False
            break
        d[s] = t
    # 変換先の重複チェック
    if len(d.values()) != len(set(d.values())):
        flg = False
    print("Yes" if flg else "No")
    return


main()

Submission status: Accepted

Solution code:
def main():
    S = input()
    T = input()
    lst = [""] * (ord("z") - ord("a") + 1)
    flg = True
    for s, t in zip(S, T):
        # 同アルファベット、違アルファベット変換チェック
        if lst[ord(s) - ord("a")] and lst[ord(s) - ord("a")] != t:
            flg = False
            break
        lst[ord(s) - ord("a")] = t
    lst = [i for i in lst if i != ""]
    # 変換先の重複チェック
    if len(lst) != len(set(lst)):
        flg = False
    print("Yes" if flg else "No")
    return


main()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    S = stdin.readline().strip()
    T = stdin.readline().strip()
    lst = [""] * (ord("z") - ord("a") + 1)
    flg = True
    for s, t in zip(S, T):
        # 同アルファベット、違アルファベット変換チェック
        if lst[ord(s) - ord("a")] and lst[ord(s) - ord("a")] != t:
            flg = False
            break
        lst[ord(s) - ord("a")] = t
    lst = [i for i in lst if i != ""]
    # 変換先の重複チェック
    if len(lst) != len(set(lst)):
        flg = False
    print("Yes" if flg else "No")
    return


main()

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
import sys
input = sys.stdin.readline





S=one_str()
T=one_str()

same_alpha_A = set(list(S))
same_alpha_B = set(list(T))
same_alpha_flg=False

if len(same_alpha_A) and len(same_alpha_A & same_alpha_B):
    same_alpha_flg=True

A_set={}
A_list=[]
for i in list(S):
    if i not in A_set:
        A_set[i]=len(A_set)+1
        
    A_list.append(A_set[i])

B_set={}
B_list=[]
for i in list(T):
    if i not in B_set:
        B_set[i]=len(B_set)+1
    B_list.append(B_set[i])

same_list_flg=True
for a,b in zip(A_list, B_list):
    if a!=b:
        same_list_flg=False
        break

if same_alpha_flg and same_list_flg:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

S = []
T = []

for i in set(s):
    S.append(s.count(i))
for j in set(t):
    T.append(t.count(j))

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

Submission status: Accepted

Solution code:
# 貪欲的アプローチで何かよくわからないが失敗
# 抽象度をあげて解決する必要があった

import collections

A = input()
B = input()

A_c = collections.Counter(A)
B_c = collections.Counter(B)
A_c = A_c.values()
B_c = B_c.values()

A_c = list(A_c)
B_c = list(B_c)
A_c.sort()
B_c.sort()
if A_c == B_c:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from sys import exit

s = input().lower()
t = input().lower()
N = len(s)

d = {}
for i in range(ord('a'), ord('z')+1):
    d[chr(i)] = -1

for i in range(N):
    if d[s[i]]==-1:
        d[s[i]] = t[i]
    else:
        if t[i] == d[s[i]]:
            pass
        else:
            print('No')
            exit()


k  = []
for i in d:
    if d[i]==-1:
        pass
    else:
        if d[i] in k:
            print('No')
            exit()
        k.append(d[i])

print('Yes')

Submission status: Accepted

Solution code:
S = input()
T = input()
s_pairs = [-1] * 26
t_pairs = [-1] * 26

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

# ペアの要素が別の文字位置でも成り立たない箇所が1つでもあれば終了
for i, s in enumerate(S):
  t = T[i]
  int_s = convert_alphabet_to_int(s)
  int_t = convert_alphabet_to_int(t)
  if s_pairs[int_s] >= 0:
    if s_pairs[int_s] != int_t:
      print('No')
      exit()
  else:
    s_pairs[int_s] = int_t
  
  if t_pairs[int_t] >= 0:
    if t_pairs[int_t] != int_s:
      print('No')
      exit()
  else:
    t_pairs[int_t] = int_s
print('Yes')

Submission status: Accepted

Solution code:
import collections
A = list(input())
B = list(input())
A_c = collections.Counter(A)
B_c = collections.Counter(B)
A_c = A_c.values()
B_c = B_c.values()
A_c = list(A_c)
B_c = list(B_c)
A_c.sort()
B_c.sort()
if A_c == B_c:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
s = input()
t = input()
n = len(s)
struct1 = []
struct2 = []
dict1 = {}
dict2 = {}
k1, k2 = 0, 0
for i in range(n):
    if s[i] not in dict1:
        dict1[s[i]] = k1
        k1 += 1    
    struct1.append(dict1[s[i]])
    if t[i] not in dict2:
        dict2[t[i]] = k2
        k2 += 1
    struct2.append(dict2[t[i]])
if struct1 == struct2:
    print ("Yes")
else:
    print ("No")

Submission status: Accepted

Solution code:
# 1対1なので決めていく
s, t = input(), input()
sd, td = {}, {}
for i in range(len(s)):
    if t[i] not in td and s[i] not in sd:
        sd[s[i]] = t[i]
        td[t[i]] = s[i]
    elif t[i] in td and s[i] in sd and td[t[i]] == s[i] and sd[s[i]] == t[i]:
        continue
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

ds = {}
dt = {}
ls = []
lt = []

for ks,kt in zip(list(s),list(t)):
    if ks not in ds:
        ds[ks] = 1
    else:
        ds[ks] += 1
    if kt not in dt:
        dt[kt] = 1
    else:
        dt[kt] += 1

for ks in ds: ls.append(ds[ks])
for kt in dt: lt.append(dt[kt])

ls.sort()
lt.sort()

if ls == lt:
    ans = "Yes"
else:
    ans = "No"

print(ans)

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
s_len = len(set(s))
t_len = len(set(t))
pare = []
for i,j in zip(s,t):
    pare.append(i+j)

if len(set(pare)) == s_len == t_len:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
s = input()
t = input()
alfa = list('abcdefghijklmnopqrstuvwxyz')
s_count = [0 for i in range(26)]
t_count = [0 for i in range(26)]
for i in range(len(s)):
    x = alfa.index(s[i])
    y = alfa.index(t[i])
    s_count[x] += 1
    t_count[y] += 1
s_count.sort()
t_count.sort()
if s_count == t_count:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

alphabet_1 = [[] for _ in range(26)]
alphabet_2 = [[] for _ in range(26)]

for i in range(len(s)):
    if alphabet_1[ord(s[i])-97] == []:
        alphabet_1[ord(s[i])-97] = t[i]
    else:
        if alphabet_1[ord(s[i])-97] == t[i]:
            continue
        else:
            print('No')
            exit()

    if alphabet_2[ord(t[i])-97] == []:
        alphabet_2[ord(t[i])-97] = s[i]
    else:
        if alphabet_2[ord(t[i])-97] == s[i]:
            continue
        else:
            print('No')
            exit()

print('Yes')

Submission status: Accepted

Solution code:
s=list(input())
t=list(input())
ss=len(set(s))
tt=len(set(t))

l=[]
for i,j in zip(s,t):
    l.append(i+j)

if len(set(l)) == ss == tt:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
import itertools
import numpy
input = sys.stdin.readline
Sa = input()
Ta = input()
S = ['0'] * len(Sa)
T = ['0'] * len(Ta)
for i in range(len(Sa)) :
    S[i] = Sa[i]
for i in range(len(Ta)) :
    T[i] = Ta[i]
ans = {}
for cs,ct in zip(S,T) :
    if cs not in ans.keys() and ct not in ans.values() :
        ans[cs] = ct
    else :
        try :
            if ans[cs] == ct :
                continue
            else :
                print("No")
                break
        except KeyError :
            print("No")
            break
else :
    print("Yes")

Submission status: Accepted

Solution code:
s = input()
t = input()
##任意の置換が可能
if len(s)!=len(t):
    print("No")
    exit()

l = len(s)

chng = {}

for i in range(l):
    if s[i] in chng:
        if chng[s[i]]!=t[i]:
            print("No")
            exit()
    else:#この置換のみ考えればよい
        chng[s[i]] = t[i]
        #これだとt[i]重複の可能性あり
chng = {}
#両方要るらしい
for i in range(l):
    if t[i] in chng:
        if chng[t[i]]!=s[i]:
            print("No")
            exit()
    else:#この置換のみ考えればよい
        chng[t[i]] = s[i]
        
    
print("Yes")

Submission status: Accepted

Solution code:
from collections import defaultdict
s=input()
t=input()
dct=defaultdict(int)
for i in range(len(s)):
  if not dct[s[i]]:
    dct[s[i]]=t[i]
  elif dct[s[i]]!=t[i]:
    print("No")
    exit()
ls=[]
for i in dct.values():
  if i in ls:
    print("No")
    exit()
  else:
    ls.append(i)
print("Yes")

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
ans = {}
for c_s, c_t in zip(S, T):
    if c_s not in ans.keys() and c_t not in ans.values():
        ans[c_s] = c_t
    else:
        try:
            if ans[c_s] == c_t:
                continue
            else:
                print("No")
                break
        except KeyError:
            print("No")
            break
else:
    print("Yes")

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):
    table = {}
    for i in range(len(T)):
        if table.get(S[i]) == None:
            table[S[i]] = T[i]
        else:
            if table[S[i]] == T[i]:
                continue
            else:
                # 同じ文字を違う文字に変換しようとしたらアウト
                print(NO)
                return

    value_list = []
    for value in table.values():
        value_list.append(value)
        
    # 違う文字を同じ文字に変換しようとしたらアウト
    if len(set(value_list)) == len(table):
        print(YES)
    else:
        print(NO)

    return

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
D, E = {}, {}
A, B = [], []
S = input()
T = input()
for i in range(len(S)):
  if S[i] in D:
    D[S[i]].append(i)
  else:
    D[S[i]] = [i]
  if T[i] in E:
    E[T[i]].append(i)
  else:
    E[T[i]] = [i]
for i in D:
  A.append(D[i])
for i in E:
  B.append(E[i])
A.sort()
B.sort()
if A == B:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

l = len(S)
d = {chr(_): chr(_) for _ in range(97,97+26)}
for i in range(l):
    now = d[S[i]]
    change = T[i]
    for k,v in d.items():
        if now == v:
            d[k] = T[i]
        if change == v:
            d[k] = now

ans = 'Yes'
for i in range(l):
    if d[S[i]] != T[i]:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

Solution code:
S = list(input())
S_dict = {}

for idx, s in enumerate(S):
    if s not in S_dict:
        S_dict[s] = [idx]
    else:
        S_dict[s].append(idx)
T = list(input())
T_dict = {}
for idx, t in enumerate(T):
    if t not in T_dict:
        T_dict[t] = [idx]
    else:
        T_dict[t].append(idx)
# print(list(S_dict.values()))
# print(list(T_dict.values()))

for s in list(S_dict.values()):
    if s in list(T_dict.values()):
        continue
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

SS = sorted(list(S))
TT = sorted(list(T))
SSS = []
TTT = []
numS = 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")