using
System;
class
GFG{
static
int
countStableNum(String str,
int
N)
{
int
[,]count1 =
new
int
[N, 10];
int
[,]count2 =
new
int
[N, 10];
for
(
int
i = 0; i < N; i++)
for
(
int
j = 0; j < 10; j++)
count1[i, j] = count2[i, j] = 0;
for
(
int
i = 0; i < N; i++)
{
if
(i != 0)
{
for
(
int
j = 0; j < 10; j++)
{
count1[i, j] += count1[i - 1, j];
}
}
count1[i, str[i] -
'0'
]++;
}
for
(
int
i = N - 1; i >= 0; i--)
{
if
(i != N - 1)
{
for
(
int
j = 0; j < 10; j++)
{
count2[i, j] += count2[i + 1, j];
}
}
count2[i, str[i] -
'0'
]++;
}
int
ans = 0;
for
(
int
i = 1; i < N - 1; i++)
{
if
(str[i] ==
'9'
)
continue
;
int
c1 = count1[i - 1, str[i] -
'0'
];
int
c2 = count2[i + 1, str[i] -
'0'
+ 1];
if
(c2 == 0)
continue
;
ans = (ans + (c1 * ((c2 * (c2 - 1) / 2))));
}
return
ans;
}
public
static
void
Main(String[] args)
{
String str =
"224353"
;
int
N = str.Length;
Console.WriteLine(countStableNum(str, N));
}
}