import java.math.BigInteger;
import java.util.HashMap;
class Ideone
{
static HashMap
<Integer, HashMap
<Integer, RationalNumber
>> cache
= new HashMap
<>();
public static void main
(String[] args
) {
for (int i = 0; i < 128; i++)
System.
out.
printf("b(%d) = %s%n", i, b
(i
)); }
static RationalNumber b(int n)
{
return b(n, 1);
}
static RationalNumber b(int n, int m)
{
HashMap
<Integer, RationalNumber
> map
= cache.
get(n
); if (map == null) cache.put(n, map = new HashMap<>());
RationalNumber rn = map.get(m);
if (rn != null) return rn;
RationalNumber i = b(n - 1, m);
RationalNumber j = b(n - 1, m + 1);
rn = new RationalNumber(a, b);
map.put(m, rn);
return rn;
}
static class RationalNumber
{
{
a = a.divide(gcd);
b = b.divide(gcd);
{
a = a.negate();
b = b.negate();
}
this.a = a;
this.b = b;
}
@Override
{
}
}
}
aW1wb3J0IGphdmEubWF0aC5CaWdJbnRlZ2VyOwppbXBvcnQgamF2YS51dGlsLkhhc2hNYXA7CgpjbGFzcyBJZGVvbmUKewogICAgc3RhdGljIEhhc2hNYXA8SW50ZWdlciwgSGFzaE1hcDxJbnRlZ2VyLCBSYXRpb25hbE51bWJlcj4+IGNhY2hlID0gbmV3IEhhc2hNYXA8PigpOwoKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpCiAgICB7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCAxMjg7IGkrKykKICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGYoImIoJWQpID0gJXMlbiIsIGksIGIoaSkpOwogICAgfQoKICAgIHN0YXRpYyBSYXRpb25hbE51bWJlciBiKGludCBuKQogICAgewogICAgICAgIHJldHVybiBiKG4sIDEpOwogICAgfQoKICAgIHN0YXRpYyBSYXRpb25hbE51bWJlciBiKGludCBuLCBpbnQgbSkKICAgIHsKICAgICAgICBIYXNoTWFwPEludGVnZXIsIFJhdGlvbmFsTnVtYmVyPiBtYXAgPSBjYWNoZS5nZXQobik7CiAgICAgICAgaWYgKG1hcCA9PSBudWxsKSBjYWNoZS5wdXQobiwgbWFwID0gbmV3IEhhc2hNYXA8PigpKTsKICAgICAgICBSYXRpb25hbE51bWJlciBybiA9IG1hcC5nZXQobSk7CiAgICAgICAgaWYgKHJuICE9IG51bGwpIHJldHVybiBybjsKICAgICAgICBpZiAobiA9PSAwKSByZXR1cm4gbmV3IFJhdGlvbmFsTnVtYmVyKEJpZ0ludGVnZXIuT05FLCBCaWdJbnRlZ2VyLnZhbHVlT2YobSkpOwogICAgICAgIFJhdGlvbmFsTnVtYmVyIGkgPSBiKG4gLSAxLCBtKTsKICAgICAgICBSYXRpb25hbE51bWJlciBqID0gYihuIC0gMSwgbSArIDEpOwogICAgICAgIEJpZ0ludGVnZXIgYSA9IGkuYS5tdWx0aXBseShqLmIpLnN1YnRyYWN0KGouYS5tdWx0aXBseShpLmIpKS5tdWx0aXBseShCaWdJbnRlZ2VyLnZhbHVlT2YobSkpOwogICAgICAgIEJpZ0ludGVnZXIgYiA9IGkuYi5tdWx0aXBseShqLmIpOwogICAgICAgIHJuID0gbmV3IFJhdGlvbmFsTnVtYmVyKGEsIGIpOwogICAgICAgIG1hcC5wdXQobSwgcm4pOwogICAgICAgIHJldHVybiBybjsKICAgIH0KCiAgICBzdGF0aWMgY2xhc3MgUmF0aW9uYWxOdW1iZXIKICAgIHsKICAgICAgICBmaW5hbCBCaWdJbnRlZ2VyIGEsIGI7CgogICAgICAgIFJhdGlvbmFsTnVtYmVyKEJpZ0ludGVnZXIgYSwgQmlnSW50ZWdlciBiKQogICAgICAgIHsKICAgICAgICAgICAgQmlnSW50ZWdlciBnY2QgPSBhLmdjZChiKTsKICAgICAgICAgICAgYSA9IGEuZGl2aWRlKGdjZCk7CiAgICAgICAgICAgIGIgPSBiLmRpdmlkZShnY2QpOwogICAgICAgICAgICBpZiAoYi5jb21wYXJlVG8oQmlnSW50ZWdlci5aRVJPKSA8IDApCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGEgPSBhLm5lZ2F0ZSgpOwogICAgICAgICAgICAgICAgYiA9IGIubmVnYXRlKCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5hID0gYTsKICAgICAgICAgICAgdGhpcy5iID0gYjsKICAgICAgICB9CgogICAgICAgIEBPdmVycmlkZQogICAgICAgIHB1YmxpYyBTdHJpbmcgdG9TdHJpbmcoKQogICAgICAgIHsKICAgICAgICAgICAgcmV0dXJuIGIuZXF1YWxzKEJpZ0ludGVnZXIuT05FKSA/IGEudG9TdHJpbmcoKSA6IFN0cmluZy5mb3JtYXQoIiVkLyVkIiwgYSwgYik7CiAgICAgICAgfQogICAgfQp9