using
System;
using
System.Text;
using
System.Collections.Generic;
public
class
GFG
{
public
static
bool
checkPairs(
char
a,
char
b)
{
if
((a ==
'1'
&& b ==
'2'
)
|| (a ==
'2'
&& b ==
'1'
))
return
true
;
else
if
((a ==
'3'
&& b ==
'4'
)
|| (a ==
'4'
&& b ==
'3'
))
return
true
;
else
if
((a ==
'5'
&& b ==
'6'
)
|| (a ==
'6'
&& b ==
'5'
))
return
true
;
else
if
((a ==
'7'
&& b ==
'8'
)
|| (a ==
'8'
&& b ==
'7'
))
return
true
;
else
if
((a ==
'0'
&& b ==
'9'
)
|| (a ==
'9'
&& b ==
'0'
))
return
true
;
return
false
;
}
public
static
int
minimiseString(
string
s)
{
Stack<
char
> st =
new
Stack<
char
>();
for
(
int
i = 0; i < s.Length; i++) {
if
(st.Count != 0
&& checkPairs(st.Peek(), s[i])) {
st.Pop();
}
else
{
st.Push(s[i]);
}
}
return
st.Count;
}
static
public
void
Main()
{
string
S =
"672183"
;
Console.WriteLine(minimiseString(S));
}
}