Buggy python submission (verdict: Runtime Error):
# -*- coding:utf-8 -*-

def calc(S, T):
    # 差を計算する
    ans = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            ans += 1
    return ans


def solve():
    s = input()
    S = [moji for moji in s]
    T = input()

    # 文字の置き換えをして、差が減ってなかったら無理？
    pre_diff = calc(S, T)
    while True:
        for i in range(len(S)):
            if S[i] != T[i]:
                c1 = S[i]
                c2 = T[i]
                break
        
        for i in range(len(S)):
            if S[i] == c1:
                S[i] = c2
            elif S[i] == c2:
                S[i] = c1
        
        # 差を計算する
        diff = calc(S, T)
        if diff == 0:
            break
        elif diff < pre_diff:
            pre_diff = diff
            continue
        else:
            print("No")
            return
    print("Yes")





if __name__ == "__main__":
    solve()

Fixed submission:
# -*- coding:utf-8 -*-

def calc(S, T):
    # 差を計算する
    ans = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            ans += 1
    return ans


def solve():
    s = input()
    S = [moji for moji in s]
    T = input()

    # 文字の置き換えをして、差が減ってなかったら無理？
    
    diff = calc(S, T)
    if diff == 0:
        print("Yes")
        return
    pre_diff = diff

    while True:
        # c1, c2を決める
        for i in range(len(S)):
            if S[i] != T[i]:
                c1 = S[i]
                c2 = T[i]
                break
        
        # 文字を置き換える
        for i in range(len(S)):
            if S[i] == c1:
                S[i] = c2
            elif S[i] == c2:
                S[i] = c1
        
        # 差を計算する
        diff = calc(S, T)
        if diff == 0:
            break
        elif diff < pre_diff:
            pre_diff = diff
            continue
        else:
            print("No")
            return
    print("Yes")





if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

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

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

    # ある文字cがsとtで場所が半端に一致していたらNO
    ans = S
    len_s = len(S)
    for i in range(len_s):
        if ans[i] != T[i]:
            c1 = ans[i]
            c2 = T[i]
            ans = ans.replace(c1, "?")
            ans = ans.replace(c2, c1)
            ans = ans.replace("?", c2)

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


def main2():
    S = input()
    T = input()

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

    # ある文字cがsとtで場所が半端に一致していたらNO
    len_s = len(S)
    for i in range(len_s):
        if not S[i] in T:
            continue
        flag1 = False
        flag2 = False
        for j in range(len_s):
            if flag1 and flag2:
                print("No")
                exit()
            if S[i] == T[j]:
                if i == j:
                    flag1 = True
                    continue
                flag2 = True
                continue
    print("Yes")



if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding:utf-8 -*-

def calc(S, T):
    # 差を計算する
    ans = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            ans += 1
    return ans


def solve():
    s = input()
    S = [moji for moji in s]
    T = input()

    # 文字の置き換えをして、差が減ってなかったら無理？
    
    diff = calc(S, T)
    if diff == 0:
        print("Yes")
        return
    pre_diff = diff

    while True:
        # c1, c2を決める
        for i in range(len(S)):
            if S[i] != T[i]:
                c1 = S[i]
                c2 = T[i]
                break
        
        # 文字を置き換える
        for i in range(len(S)):
            if S[i] == c1:
                S[i] = c2
            elif S[i] == c2:
                S[i] = c1
        
        # 差を計算する
        diff = calc(S, T)
        if diff == 0:
            break
        elif diff < pre_diff:
            pre_diff = diff
            continue
        else:
            print("No")
            return
    print("Yes")





if __name__ == "__main__":
    solve()