All problems

Problem 322

Determine if Two Strings Are Close

Medium · 20 pts · String, Hash Table, Sorting

Problem

Two strings are close if you can turn one into the other using these operations any number of times. Operation 1: swap any two characters (so the order never matters). Operation 2: pick two letters that both already occur in the string and swap all their occurrences, for example every 'a' becomes 'b' and every 'b' becomes 'a'. Decide whether strings A and B are close.

Input

Two lines: string A and string B, both of lowercase letters.

Output

Print YES if the strings are close, otherwise NO.

Constraints

1 <= |A|, |B| <= 100000

Example input

abc
bca

Example output

YES

Explanation

'abc' and 'bca' use the same letters with the same counts, so swaps alone (operation 1) turn one into the other: the answer is YES.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Reverse Vowels of a String Next: Longest Palindrome from Letters