digit dp + calculation