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: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

s = S()
t = S()
l = len(s)
S_Alphabet = [set() for _ in range(26)]
T_Alphabet = [set() for _ in range(26)]
# ord('a') = 97
for i in range(l):
    S_Alphabet[ord(s[i])-97].add(i)
    T_Alphabet[ord(t[i])-97].add(i)
    if S_Alphabet[ord(s[i])-97] != T_Alphabet[ord(t[i])-97]:
        print("No")
        exit()
else:
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
s = input()
t = input()
n = len(s)
yes = True
for i in range(n):
    for j in range(i + 1, n):
        if (s[i] == s[j]) != (t[i] == t[j]):
            yes = False
            break
if yes:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
S = input()
T = input()
N = len(S)
done_alphabets = []

for i in range(N):
    if S[i] in done_alphabets:
        continue
    if S[i] != T[i]:
        memo_char_num = []
        for j in range(i+1, N):
            if T[j] == T[i]:
                memo_char_num.append(j)
        for k in range(i+1, N):
            if k in memo_char_num:
                if S[i] != S[k]:
                    print("No")
                    quit()
            else:
                if S[i] == S[k]:
                    print("No")
                    quit()
        done_alphabets.append(S[i])
        done_alphabets.append(T[i])

print("Yes")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

S = input()
T = input()

if S==T:
    print("Yes")
    exit()

ls = []
for i in range(len(S)):
    s = S[i]
    t = T[i]
    if s==t:
        pass
    else:
        ls.append(t)
        S = S.replace(t,"?")
        S = S.replace(s,t)
        S = S.replace("?",s)
        # print(S)
        if S==T:
            print("Yes")
            exit()
print("No")
exit()

Submission status: Time Limit Exceeded

Solution code:
s=input()
t=input()
st={}
for i in range(len(s)):
    if s[i]!=t[i]:
        si=s[i]
        ti=t[i]
        s=s.replace(si,'0')
        s=s.replace(ti,si)
        s=s.replace('0',ti)
print('Yes' if s==t else 'No')
#print(s,t)

Submission status: Time Limit Exceeded

Solution code:
def str_to_map(str):
    Map = dict()
    for i in range(len(str)):
        c = str[i]
        if(c in Map):
            Map[c].add(i)
        else:
            Map[c] = {i}
    return Map


str1 = input()
str2 = input()

I1 = str_to_map(str1)
I2 = str_to_map(str2)

flag = True

for i in range(len(str1)):
    if(I1[str1[i]] != I2[str2[i]]):
        flag = False

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)

def main():
    S = input()
    T = input()
    for i in range(len(S)):
        if S[i] != T[i]:
            S = S.translate(str.maketrans({S[i]: T[i], T[i]: S[i]}))
    
    if S == T:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
T = input()
for i in range(len(S)):
  if S[i] != T[i]:
    tmp1 = S[i]
    tmp2 = T[i]
    S = S.replace(tmp1, "0")
    S = S.replace(tmp2, "1")
    S = S.replace("0", tmp2)
    S = S.replace("1", tmp1)
print("Yes" if S == T else "No")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

s = list(input())
t = list(input())
base_s = np.zeros(len(s))
base_t = np.zeros(len(t))
judge_s = []
judge_t = []
ans = "Yes"

for i in range(len(s)):
  base_s[i] = ord(s[i]) -97
  base_t[i] = ord(t[i]) -97
  
for i in range(26):
  temp_s = list(np.where(base_s == i, 1, 0))
  temp_t = list(np.where(base_t == i, 1, 0))
  sum_s = np.sum(temp_s)
  sum_t = np.sum(temp_t)
  if (sum_t > 1):
    judge_t.append(temp_t)
  if (sum_s > 1):
    judge_s.append(temp_s)
    
judge_s.sort()
judge_t.sort()
    
if judge_s != judge_t:
  ans = "No"
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

s = list(input())
t = list(input())
base_s = np.zeros(len(s))
base_t = np.zeros(len(t))
judge_s = []
judge_t = []
ans = "Yes"

for i in range(len(s)):
  base_s[i] = ord(s[i]) -97
  base_t[i] = ord(t[i]) -97
  
for i in range(26):
  temp_s = list(np.where(base_s == i, 1, 0))
  temp_t = list(np.where(base_t == i, 1, 0))
  judge_s.append(temp_s)
  judge_t.append(temp_t)
    
judge_s.sort()
judge_t.sort()
    
if judge_s != judge_t:
  ans = "No"
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
S = sorted(list(input()))
T = sorted(list(input()))

tmp = copy.copy(S)
for i in tmp:
    if i in T:
        S.remove(i)
        T.remove(i)
if len(set(S)) == len(set(T)):
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
S = input().strip()
T = input().strip()

for i in range(len(S)):
    S = S.translate(str.maketrans({S[i]: T[i], T[i]: S[i]}))

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

S = stdin.readline().rstrip()
T = stdin.readline().rstrip()

for i in range(len(S)):
    if S[i] != T[i]:
        S = S.translate(str.maketrans({S[i]: T[i], T[i]: S[i]}))

# print(S, T)

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

Submission status: Time Limit Exceeded

Solution code:
import collections
S = input()
T = input()
N = len(S)
ss = set(S)
st = set(T)


sa = [0]*N
ta = [0]*N
table = collections.defaultdict(set)
table2 = collections.defaultdict(set)

for i, xy in enumerate(zip(S, T)):
    x, y = xy
    table[x].add(i)
    table2[y].add(i)

flag = True
for x, y in zip(S, T):

    if table[x] == table2[y]:
        continue
    else:
        flag = False
        break

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

Submission status: Time Limit Exceeded

Solution code:
import sys 
s=input()
t=input()
n=len(s)
for i in range(n):
        for j in range(i,n):
          if s[i]==s[j] and t[i]!=t[j]:
              print("No")
              exit()
          if s[i]!=s[j] and t[i]==t[j]:
              print("No")
              exit()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
SS = input()
TT = input()


def main():

    S = ''
    T = ''

    list_index = []
    for i, s in enumerate(SS):
        if SS.count(s) > 1:
            list_index.append(i)
    for i, t in enumerate(TT):
        if TT.count(t) > 1:
            list_index.append(i)
    for idx in list_index:
        S += SS[idx]
        T += TT[idx]

    for i, s1 in enumerate(S):
        list_index = []
        for j, s2 in enumerate(S[i + 1:]):
            if s1 == s2:
                list_index.append(j + 1 + i)

        if len(list_index):
            t1 = T[i]
            for idx in list_index:
                # print(i, ',', s1, ',', j, ',', s2, ',', idx)
                t2 = T[idx]
                if t1 != t2:
                    print('No')
                    return
        else:
            for k, t3 in enumerate(T):
                list_index = []
                for l, t4 in enumerate(T[k + 1:]):
                    if t3 == t4:
                        list_index.append(l + 1 + k)
                if len(list_index):
                    u1 = S[k]
                    for idx in list_index:
                        u2 = S[idx]
                        if u1 != u2:
                            print('No')
                            return

    print('Yes')


main()

Submission status: Time Limit Exceeded

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


def main():
    for i, s1 in enumerate(S):
        list_index = []
        for j, s2 in enumerate(S[i + 1:]):
            if s1 == s2:
                list_index.append(j + 1 + i)

        if len(list_index):
            t1 = T[i]
            for idx in list_index:
                # print(i, ',', s1, ',', j, ',', s2, ',', idx)
                t2 = T[idx]
                if t1 != t2:
                    print('No')
                    return
        else:
            for k, t3 in enumerate(T):
                list_index = []
                for l, t4 in enumerate(T[k + 1:]):
                    if t3 == t4:
                        list_index.append(l + 1 + k)
                if len(list_index):
                    u1 = S[k]
                    for idx in list_index:
                        u2 = S[idx]
                        if u1 != u2:
                            print('No')
                            return

    print('Yes')


main()

Submission status: Time Limit Exceeded

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

S_dict = dict()
T_dict = dict()

for character in [chr(i) for i in range(97, 97+26)]:
    S_dict[character] = set()
    T_dict[character] = set()    

for i in range(N):
    S_dict[S[i]].add(i)
    T_dict[T[i]].add(i)

for i in range(N):
    if S[i]!=T[i]:
        target_left = S[i]
        target_right = T[i]
        #print(S)
        #print(S[i],"⇔",T[i],":",S_dict[target_left],"⇔",S_dict[target_right])
        for place in S_dict[target_left]:
            S[place] = target_right
            
        for place in S_dict[target_right]:
            S[place] = target_left
            
        store = S_dict[target_left]
        S_dict[target_left] = S_dict[target_right]
        S_dict[target_right] = store

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
s = input()
t = input()
s_idx = [""]*26
t_idx = [""]*26
for i in range(len(s)):
    s_idx[ord(s[i])-97] += str(i)
for i in range(len(s)):
    t_idx[ord(t[i])-97] += str(i)
s_idx.sort()
t_idx.sort()
if s_idx == t_idx:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
s = input()
t = input()
s_idx = ["a"]*26
t_idx = ["a"]*26
for i in range(len(s)):
    s_idx[ord(s[i])-97] += str(i)
for i in range(len(s)):
    t_idx[ord(t[i])-97] += str(i)
for i in range(26):
    if s_idx[i] in t_idx:
        continue
    else:
        print("No")
        exit()
#print(s_idx,t_idx)
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
T = str(input())
alp = "abcdefghijklmnopqrstuvwxyz"
for i in range(0,len(S)):
  alp.replace(S[i],"")
  if S[i] != T[i]:
    S = S.translate(str.maketrans({S[i]:T[i], T[i]:S[i]}))
  else:
    pass
  if S == T:
    print("Yes")
    exit()
  if alp == "":
    break
print("No")

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
T = str(input())
alp = "abcdefghijklmnopqrstuvwxyz"
for i in range(0,min(len(S),len(alp)**2)):
  if S[i] != T[i]:
    S = S.translate(str.maketrans({S[i]:T[i], T[i]:S[i]}))
  else:
    pass
  if S == T:
    print("Yes")
    exit()
print("No")

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
T = str(input())
alp = "abcdefghijklmnopqrstuvwxyz"
for i in range(0,min(len(S),10**5)):
  if S[i] != T[i]:
    S = S.translate(str.maketrans({S[i]:T[i], T[i]:S[i]}))
  if S == T:
    print("Yes")
    exit()
print("No")

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
T = str(input())
alp = "abcdefghijklmnopqrstuvwxyz"
for i in range(0,len(S)):
  if S[i] != T[i]:
    S = S.translate(str.maketrans({S[i]:T[i], T[i]:S[i]}))
  if S == T:
    print("Yes")
    exit()
print("No")

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
T=list(input())
As={chr(ord('a')+i):[] for i in range(26)}
At={chr(ord('a')+i):[] for i in range(26)}

ans='Yes'
if len(set(S))==len(set(T)):
    for i in range(len(S)):
        As[S[i]].append(i)
        At[T[i]].append(i)
        if As[S[i]]!=At[T[i]]:
            ans='No'
            break
else:
    ans='No'

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
s = input()
t = input()
d = defaultdict(set)
e = defaultdict(set)
for i in range(len(s)):
    d[s[i]].add(i)
    e[t[i]].add(i)
ans = True
for i in range(len(s)):
    if e[t[i]] != d[s[i]]:
        ans = False
print("Yes" if ans else "No")

Submission status: Time Limit Exceeded

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


for i,j in zip(S,T):
    if S.count(i) == T.count(j):
        pass
    else:
        print("No")
        break
else:
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

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

G = []
G.append(["zz","zz"])
for i in range(len(S)):
    G.append([S[i],T[i]])
#print(G)

cnt = 0
for i in range(len(G)-1):
    G = sorted(G, key=itemgetter(0))
    if G[i+1][0] == G[i][0]:
        if G[i+1][1] != G[i][1]:
            cnt +=1
            break
    G = sorted(G, key=itemgetter(1))
    if G[i+1][1] == G[i][1]:
        if G[i+1][0] != G[i][0]:
            cnt +=1
            break
print('Yes' if cnt == 0 else 'No')

Submission status: Time Limit Exceeded

Solution code:

from operator import itemgetter
S = input()
T = input()
S1 = list(S)

T1 = list(T)

G = []
G.append(["zz","zz"])
for i in range(len(S)):
    G.append([S1[i],T1[i]])

cnt = 0
for i in range(len(G)-1):
    G = sorted(G, key=itemgetter(0))
    if G[i+1][0] == G[i][0]:
        if G[i+1][1] != G[i][1]:
            cnt +=1
            break
for i in range(len(G)-1):
    G = sorted(G, key=itemgetter(1))
    if G[i+1][1] == G[i][1]:
        if G[i+1][0] != G[i][0]:
            cnt +=1
            break
print('Yes' if cnt == 0 else 'No')

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter
S = input()
T = input()
S1 = list(S)

T1 = list(T)

G = []
G.append(["zz","zz"])
for i in range(len(S)):
    G.append([S1[i],T1[i]])

cnt = 0
for i in range(len(G)-1):
    G = sorted(G, key=itemgetter(0))
    if G[i+1][0] == G[i][0]:
        if G[i+1][1] != G[i][1]:
            cnt +=1
for i in range(len(G)-1):
    G = sorted(G, key=itemgetter(1))
    if G[i+1][1] == G[i][1]:
        if G[i+1][0] != G[i][0]:
            cnt +=1 
print('Yes' if cnt == 0 else 'No')

Submission status: Time Limit Exceeded

Solution code:
S = input()
T = input()
def swap(x, p, q):
  x_neo = ""
  for i in x:
    if i == p:
      x_neo += q
    elif i == q:
      x_neo += p
    else:
      x_neo += i
  return x_neo
for i in range(len(S)):
  if S[i] != T[i]:
    S = swap(S, S[i], T[i])
#    print(S)
if S == T:
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
S = input()
T = input()
flg_s = [0] * len(S)
flg_t = [0] * len(T)
ans = "Yes"

for i in range(len(S)):
    if S.count(S[i]) > 1:
        flg_s[i] = 1

for i in range(len(T)):
    if T.count(T[i]) > 1:
        flg_t[i] = 1

for i in range(len(S)):
    if flg_s[i] != flg_t[i]:
        ans = "No"
print(ans)

Submission status: Time Limit Exceeded

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

    for i in range(len(S)):
        tmp = S[i]
        S = S.replace(T[i],'_')
        S = S.replace(S[i],T[i])
        S = S.replace('_',tmp)
    if S == T:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

ans = "Yes"

for i in range(len(s)-1):
    if s[i]!=t[i]:
        s_same = s[i+1:].find(s[i])
        t_same = t[i+1:].find(t[i])
        if s_same!=t_same:
            ans="No"
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
t = input()
l = ["0"]*len(s)
if len(set(s)) != len(set(t)):
  print("No")
  exit()
for i in range(len(s)):
  if s[i] == t[i]:
    l[i] = t[i]
for i in range(len(s)):
  if s[i] != t[i] and t[i] in l:
    print("No")
    exit()
print("Yes")

Submission status: Time Limit Exceeded

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

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

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

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

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

print(ans())

Submission status: Time Limit Exceeded

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

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

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

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

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

print(ans())

Submission status: Time Limit Exceeded

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

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

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

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

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

print(ans())

Submission status: Time Limit Exceeded

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

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

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

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

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

print(ans())

Submission status: Time Limit Exceeded

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


for i in range(len(S)):
    if(S.count(S[i])>1):
        t=T[i]
        for j in range(i+1,len(S)):
            if(S[i]==S[j]):
                if(T[i]!=T[j]):
                    print("No")
                    exit()
for i in range(len(S)):
    if(T.count(T[i])>1):
        t=S[i]
        for j in range(i+1,len(S)):
            if(T[i]==T[j]):
                if(S[i]!=S[j]):
                    print("No")
                    exit()

print("Yes")

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

S=input()
T=input()

while len(S)>0:
  s=S[0]
  S=S[1:]
  ids=S.find(s)
  t=T[0]
  T=T[1:]
  idt=T.find(t)
  
  if ids != idt:
    print('No')
    break
if len(S)==0:
  print('Yes')

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
T=str(input())
C=[S]
for i in range(len(S)):
  U=str()
  if C[-1][i]!=T[i]:
    for j in range(len(S)):
      if C[-1][j]==C[-1][i]:
        U +=T[i]
      elif C[-1][j]==T[i]:
        U +=C[-1][i]
      else:
        U +=C[-1][j]
    C +=[U]
print('Yes' if T==C[-1] else 'No')

Submission status: Time Limit Exceeded

Solution code:
import collections

x = input()
y = input()

c = collections.Counter(x)
d = collections.Counter(y)

chars = []
for i in c.items():
    if i[1] >= 2:
        chars.append(i[0])
for j in d.items():
    if j[1] >= 2:
        chars.append(j[0])

chars = list(set(chars))



for i in chars:
    li = []
    li_2 = []
    for j in range(len(x)):
        if i == x[j]:
            li.append(y[j])
        elif i == y[j]:
            li_2.append(x[j])
        if len(li) >= 2:
            if len(list(set(li))) == 1:
                continue
            else:
                print('No')
                exit()
        elif len(li_2) >= 2:
            if len(list(set(li_2))) == 1:
                continue
            else:
                print('No')
                exit()

print('Yes')

Submission status: Time Limit Exceeded

Solution code:
x = input()
y = input()


for i in range(97,123):
    li = []
    li_2 = []
    for j in range(len(x)):
        if chr(i) == x[j]:
            li.append(y[j])
        elif chr(i) == y[j]:
            li_2.append(x[j])
        if len(li) >= 2:
            if len(list(set(li))) == 1:
                continue
            else:
                print('No')
                exit()
        elif len(li_2) >= 2:
            if len(list(set(li_2))) == 1:
                continue
            else:
                print('No')
                exit()

print('Yes')

Submission status: Time Limit Exceeded

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

for i in range(len(s)):
    if s[i] != t[i]:
        s = s.translate(str.maketrans({s[i]: t[i], t[i]: s[i]}))
    else:
        continue

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

Submission status: Time Limit Exceeded

Solution code:
def func(S,N):
    dic = {'a':'','b':'','c':'','d':'','e':'','f':'','g':'','h':'','i':'','j':'','k':'','l':'','m':'','n':'','o':'','p':'','q':'','r':'','s':'','t':'','u':'','v':'','w':'','x':'','y':'','z':''}
    for i in range(N):
        dic[S[i]] = dic[S[i]] + str(i)
    tmp = []
    for value in dic.values():
        if value == '':
            continue
        tmp.append(int(value))
    tmp.sort()
    return tmp
S = input()
T = input()
N = len(S)
if func(S,N) == func(T,N):
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
def func(S,N):
    dic = {}
    for i in range(N):
        if dic.get(S[i],False):
            dic[S[i]] = dic[S[i]] + str(i)
        else:
            dic[S[i]] = str(i)
    tmp = []
    for value in dic.values():
        tmp.append(int(value))
    tmp.sort()
    return tmp
S = input()
T = input()
N = len(S)
if func(S,N) == func(T,N):
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
def func(S,N):
    dic = {}
    for i in range(N):
        if S[i] in dic:
            dic[S[i]] = dic[S[i]] + str(i)
        else:
            dic[S[i]] = str(i)
    tmp = []
    for value in dic.values():
        tmp.append(int(value))
    tmp.sort()
    return tmp
S = input()
T = input()
N = len(S)
if func(S,N) == func(T,N):
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

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

con = 0

ans = "Yes"

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s, t = input(), input()
for i in range(len(s)):
  if s[i] != t[i]:
    a = s[i]
    b = t[i]
    s = s.translate(str.maketrans({a: b, b: a}))
  if s[:i+1] != t[:i+1]:
    print("No")
    exit()
print("Yes")