import
java.util.*;
class
GFG{
static
class
pair
{
int
first, second;
public
pair(
int
first,
int
second)
{
this
.first = first;
this
.second = second;
}
@Override
public
int
hashCode() {
final
int
prime =
31
;
int
result =
1
;
result = prime * result + first;
result = prime * result + second;
return
result;
}
@Override
public
boolean
equals(Object obj) {
if
(
this
== obj)
return
true
;
if
(obj ==
null
)
return
false
;
if
(getClass() != obj.getClass())
return
false
;
pair other = (pair) obj;
if
(first != other.first)
return
false
;
if
(second != other.second)
return
false
;
return
true
;
}
}
static
boolean
canBecomeEqual(String A, String B)
{
if
(A.length() != B.length()) {
return
false
;
}
if
(A == B) {
return
true
;
}
int
[]b =
new
int
[
26
];
for
(
int
i =
0
; i < A.length(); i++) {
b[B.charAt(i) -
'a'
] = i;
}
HashMap<Character,Integer> mp1, mp2;
mp1 =
new
HashMap<Character,Integer>();
mp2 =
new
HashMap<Character,Integer>();
int
diff =
0
;
HashSet<pair> positions =
new
HashSet<pair>();
for
(
int
i =
0
; i < A.length(); ++i) {
if
(A.charAt(i) != B.charAt(i)) {
positions.add(
new
pair(i, b[A.charAt(i) -
'a'
] ));
diff++;
}
if
(mp1.containsKey(A.charAt(i))){
mp1.put(A.charAt(i), mp1.get(A.charAt(i))+
1
);
}
else
{
mp1.put(A.charAt(i),
1
);
}
if
(mp2.containsKey(B.charAt(i))){
mp2.put(B.charAt(i), mp2.get(B.charAt(i))+
1
);
}
else
{
mp2.put(B.charAt(i),
1
);
}
}
if
(diff <=
3
&& mp1 == mp2) {
return
true
;
}
if
(diff ==
4
&& mp1 == mp2) {
for
(pair x : positions) {
pair search
=
new
pair( x.second, x.first );
if
(!positions.contains(search)) {
return
false
;
}
}
return
true
;
}
return
false
;
}
public
static
void
main(String[] args)
{
String A =
"abcd"
;
String B =
"cdba"
;
if
(canBecomeEqual(A, B)) {
System.out.print(
"Yes"
+
"\n"
);
}
else
{
System.out.print(
"No"
+
"\n"
);
}
}
}