using
System;
using
System.Collections.Generic;
class
GFG
{
public
static
int
[, , ,] dp =
new
int
[100, 100, 2, 2];
public
static
String X =
""
, Y =
""
, Z =
""
;
public
static
int
XSize, YSize, ZSize;
public
static
int
boolToInt(
bool
input){
if
(input)
return
1;
return
0;
}
public
static
int
countOfSubsequence(
int
idx1,
int
idx2,
bool
bound1,
bool
bound2)
{
if
(idx1 == XSize) {
if
(idx2 == 0)
return
0;
if
(!bound1 || idx2 >= YSize)
return
1;
return
0;
}
if
(dp[idx1, idx2, boolToInt(bound1), boolToInt(bound2)] != -1) {
return
dp[idx1, idx2, boolToInt(bound1), boolToInt(bound2)];
}
int
ans = countOfSubsequence(idx1 + 1, idx2, bound1, bound2);
int
isOk = 0;
if
(!bound1) {
++isOk;
}
else
if
(idx2 >= YSize || X[idx1] >= Y[idx2]){
++isOk;
bound1 &= (idx2 < YSize && X[idx1] == Y[idx2]);
}
if
(!bound2) {
++isOk;
}
else
if
(idx2 < ZSize && X[idx1] <= Z[idx2]) {
++isOk;
bound2 &= (X[idx1] == Z[idx2]);
}
if
(isOk == 2) {
ans += countOfSubsequence(idx1 + 1, idx2 + 1, bound1, bound2);
}
return
dp[idx1, idx2, boolToInt(bound1), boolToInt(bound2)] = ans;
}
public
static
int
UtilCountOfSubsequence()
{
for
(
int
i=0 ; i<100 ; i++){
for
(
int
j=0 ; j<100 ; j++){
for
(
int
k=0 ; k<2 ; k++){
for
(
int
l=0 ; l<2 ; l++){
dp[i, j, k, l] = -1;
}
}
}
}
XSize = X.Length;
YSize = Y.Length;
ZSize = Z.Length;
return
countOfSubsequence(0, 0,
true
,
true
);
}
public
static
void
Main(
string
[] args){
X =
"abc"
;
Y =
"a"
;
Z =
"bc"
;
if
(Y.CompareTo(Z) > 0) {
Console.Write(0);
return
;
}
Console.Write(UtilCountOfSubsequence());
}
}