using
System;
class
Program
{
const
int
MaxLength = 222;
const
int
AlphabetSize = 26;
static
bool
[,,] dp =
new
bool
[MaxLength, AlphabetSize, AlphabetSize];
static
Tuple<Tuple<
int
,
int
>,
int
>[,,] parent =
new
Tuple<Tuple<
int
,
int
>,
int
>[MaxLength, AlphabetSize, AlphabetSize];
static
void
Main()
{
int
n = 9;
string
s =
"abacbecfd"
;
dp[0, 0, 0] =
true
;
for
(
int
i = 0; i < n; ++i)
{
int
currentChar = s[i] -
'a'
;
for
(
int
color1 = 0; color1 < AlphabetSize; ++color1)
{
for
(
int
color2 = 0; color2 < AlphabetSize; ++color2)
{
if
(!dp[i, color1, color2])
continue
;
if
(currentChar >= color1)
{
dp[i + 1, currentChar, color2] =
true
;
parent[i + 1, currentChar, color2] =
new
Tuple<Tuple<
int
,
int
>,
int
>(
new
Tuple<
int
,
int
>(color1, color2), 0);
}
if
(currentChar >= color2)
{
dp[i + 1, color1, currentChar] =
true
;
parent[i + 1, color1, currentChar] =
new
Tuple<Tuple<
int
,
int
>,
int
>(
new
Tuple<
int
,
int
>(color1, color2), 1);
}
}
}
}
int
lastColor1 = -1, lastColor2 = -1;
for
(
int
color1 = 0; color1 < AlphabetSize; ++color1)
{
for
(
int
color2 = 0; color2 < AlphabetSize; ++color2)
{
if
(dp[n, color1, color2])
{
lastColor1 = color1;
lastColor2 = color2;
}
}
}
if
(lastColor1 == -1)
{
Console.WriteLine(
"NO"
);
return
;
}
string
coloring =
""
;
for
(
int
i = n; i > 0; --i)
{
int
prevColor1 = parent[i, lastColor1, lastColor2].Item1.Item1;
int
prevColor2 = parent[i, lastColor1, lastColor2].Item1.Item2;
if
(parent[i, lastColor1, lastColor2].Item2 == 1)
{
coloring +=
'1'
;
}
else
{
coloring +=
'0'
;
}
lastColor1 = prevColor1;
lastColor2 = prevColor2;
}
char
[] reversedColoring = coloring.ToCharArray();
Array.Reverse(reversedColoring);
coloring =
new
string
(reversedColoring);
Console.WriteLine(
"YES"
);
Console.WriteLine(coloring);
}
}