import
java.util.*;
public
class
GFG
{
static
void
runLengthEncoding(
String S, ArrayList<pair<Character, Integer> > V)
{
int
count =
1
;
for
(
int
i =
1
; i < S.length(); i++) {
if
(S.charAt(i) != S.charAt(i -
1
)) {
V.add(
new
pair<Character, Integer>(
S.charAt(i -
1
), count));
count =
0
;
}
count++;
}
V.add(
new
pair<Character, Integer>(
S.charAt(S.length() -
1
), count));
}
static
boolean
isPossible(String A, String B)
{
ArrayList<pair<Character, Integer> > V1
=
new
ArrayList<pair<Character, Integer> >();
ArrayList<pair<Character, Integer> > V2
=
new
ArrayList<pair<Character, Integer> >();
runLengthEncoding(A, V1);
runLengthEncoding(B, V2);
if
(V1.size() != V2.size()) {
return
false
;
}
for
(
int
i =
0
; i < V1.size(); i++) {
if
(V1.get(i).first != V2.get(i).first) {
return
false
;
}
if
(!(V1.get(i).second == V2.get(i).second
|| (V1.get(i).second < V2.get(i).second
&& V1.get(i).second >=
2
))) {
return
false
;
}
}
return
true
;
}
public
static
void
main(String[] args)
{
String A =
"abbaac"
;
String B =
"abbbbaaac"
;
boolean
answer = isPossible(A, B);
if
(answer ==
true
) {
System.out.println(
"YES"
);
}
else
{
System.out.println(
"NO"
);
}
}
}
class
pair<T, U> {
T first;
U second;
public
pair(T first, U second)
{
this
.first = first;
this
.second = second;
}
}