P23077 [AtCoder] Friendly Strings
普及+
题目描述

Problem Description

(21:13 Update) A test case where |A|=|B|=1 was included during the testing phase, so we will rejudge. Note that this case does not affect programs that output NO.

Two strings $ A $ and $ B $ are called friendly strings if string $ A $ can be converted into string $ B $ by exactly 3 swaps.

A swap refers to exchanging two characters in a string. For example, in the string abc, you can swap a and c to convert it to cba.

For a string like aa, swapping the first a with the second a is allowed, but specifying the same position is not allowed.

Given strings $ A $ and $ B $, determine if they are friendly strings.

Input Format

The input is given from the standard input in the following format:

$ A $ $ B $

  • The first line contains string $A\ (2\ ≦\ |A|≦\ 1000)$.
  • The second line contains string $B\ (|B|\ =\ |A|)$.
  • Both $ A $ and $ B $ are guaranteed to consist only of lowercase alphabets.

Output Format

Output YES if the given two strings are friendly strings, otherwise output NO. End the output with a newline.

Sample Input and Output

Sample Input #1

abcdef
fedcba

Sample Output #1

YES

Sample Input #2

abababab
babababa

Sample Output #2

NO

Sample Input #3

nt
nt

Sample Output #3

NO

Sample Input #4

pqqq
pqqq

Sample Output #4

YES

Sample Input #5

abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvxyzw
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz

Sample Output #5

YES

Sample Input #6

abcdef
ghijkl

Sample Output #6

NO

Notes/Hints

Sample Explanation 1

First, swap a and f in string $ A $ abcdef to get fbcdea. Then, swap b and e to get fecdba. Finally, swap c and d to get fedcba, which matches string $ B $. Therefore, these two strings are friendly strings, so output YES.

Sample Explanation 2

Even if the used characters are the same, there are patterns that cannot be made into the same string with 3 swaps.

Sample Explanation 3

There is only one way to swap, and after repeating 3 swaps, it becomes tn. Therefore, although they are the same two strings, they are not friendly strings.

Sample Explanation 4

First, swap the first and second characters to get qpqq. Then, swap the third and fourth characters to get qpqq. This is allowed even if the same characters are chosen but in different positions. Finally, swap the first and second characters again to get pqqq.

Sample Explanation 5

Be aware that long strings may be given.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
abcdef fedcba
样例输出
YES