import
java.util.*;
class
GfG {
static
int
dp[][][][] =
new
int
[
64
][
64
][
64
][
2
];
static
int
func(
int
third,
int
seta,
int
setb,
int
carry,
int
number)
{
if
(dp[third][seta][setb][carry] != -
1
)
return
dp[third][seta][setb][carry];
int
shift = (number >> third);
if
(shift ==
0
&& seta ==
0
&& setb ==
0
&& carry ==
0
)
return
1
;
if
(shift ==
0
|| seta <
0
|| setb <
0
)
return
0
;
int
mask = shift &
1
;
dp[third][seta][setb][carry] =
0
;
if
((mask ==
1
) && carry ==
1
) {
dp[third][seta][setb][carry]
+= func(third +
1
, seta, setb,
0
, number)
+ func(third +
1
, seta -
1
, setb -
1
,
1
, number);
}
else
if
(mask ==
1
&& carry ==
0
) {
dp[third][seta][setb][carry]
+= func(third +
1
, seta -
1
, setb,
0
, number)
+ func(third +
1
, seta, setb -
1
,
0
, number);
}
else
if
(mask ==
0
&& carry ==
1
) {
dp[third][seta][setb][carry] += func(third +
1
, seta -
1
, setb,
1
, number)
+ func(third +
1
, seta, setb -
1
,
1
, number);
}
else
if
(mask ==
0
&& carry ==
0
) {
dp[third][seta][setb][carry] += func(third +
1
, seta, setb,
0
, number)
+ func(third +
1
, seta -
1
, setb -
1
,
1
, number);
}
return
dp[third][seta][setb][carry];
}
static
int
possibleSwaps(
int
a,
int
b,
int
c)
{
for
(
int
q =
0
; q <
64
; q++)
{
for
(
int
r =
0
; r <
64
; r++)
{
for
(
int
p =
0
; p <
64
; p++)
{
for
(
int
d =
0
; d <
2
; d++)
{
dp[q][r][p][d] = -
1
;
}
}
}
}
int
ans = func(
0
, a, b,
0
, c);
return
ans;
}
public
static
void
main(String[] args)
{
int
x =
2
, y =
2
, c =
20
;
System.out.println(possibleSwaps(x, y, c));
}
}