def main():

    import collections

    S = eval(input())

    T = eval(input())



    table = collections.defaultdict(set)

    table2 = collections.defaultdict(set)

    a = []

    b = []



    for i, xy in enumerate(zip(S, T)):

        x, y = xy

        if x not in table:

            a.append(i)

        if y not in table2:

            b.append(i)



        table[x].add(i)

        table2[y].add(i)



    flag = True



    if a != b:

        flag = False



    for i in a:

        if flag:

            if table[S[i]] == table2[T[i]]:

                continue

            else:

                flag = False

                break

    if flag:

        print("Yes")

    else:

        print("No")





main()

def main():

    import collections

    S = eval(input())

    T = eval(input())

    N = len(S)

    table = collections.defaultdict(int)

    table2 = collections.defaultdict(int)

    flag = True

    for i in range(N):

        x = S[i]

        y = T[i]



        if x in table:

            if y == T[table[x]]:

                continue

            else:

                flag = False

                break

        else:

            if y in table2:

                flag = False

                break

            table[x] = i

            table2[y] = i



    if flag:

        print("Yes")

    else:

        print("No")





main()

def main():
    import collections

    S = eval(input())
    T = eval(input())
    table = collections.defaultdict(set)
    table2 = collections.defaultdict(set)
    a = []
    b = []
    for i, xy in enumerate(zip(S, T)):
        x, y = xy
        if x not in table:
            a.append(i)
        if y not in table2:
            b.append(i)
        table[x].add(i)
        table2[y].add(i)
    flag = True
    if a != b:
        flag = False
    for i in a:
        if flag:
            if table[S[i]] == table2[T[i]]:
                continue
            else:
                flag = False
                break
    if flag:
        print("Yes")
    else:
        print("No")


main()

def main():
    import collections

    S = eval(input())
    T = eval(input())
    N = len(S)
    table = collections.defaultdict(int)
    table2 = collections.defaultdict(int)
    flag = True
    for i in range(N):
        x = S[i]
        y = T[i]
        if x in table:
            if y == T[table[x]]:
                continue
            else:
                flag = False
                break
        else:
            if y in table2:
                flag = False
                break
            table[x] = i
            table2[y] = i
    if flag:
        print("Yes")
    else:
        print("No")


main()

-    table = collections.defaultdict(set) -    table2 = collections.defaultdict(set) -    a = [] -    b = [] -    for i, xy in enumerate(zip(S, T)): -        x, y = xy -        if x not in table: -            a.append(i) -        if y not in table2: -            b.append(i) -        table[x].add(i) -        table2[y].add(i) +    N = len(S) +    table = collections.defaultdict(int) +    table2 = collections.defaultdict(int) -    if a != b: -        flag = False -    for i in a: -        if flag: -            if table[S[i]] == table2[T[i]]: +    for i in range(N): +        x = S[i] +        y = T[i] +        if x in table: +            if y == T[table[x]]: +        else: +            if y in table2: +                flag = False +                break +            table[x] = i +            table2[y] = i