Dynamic programming/BigInteger