There were two questions. 1 hours 30 mins to complete both of them.
Explanation for 16, 1…14->41->42 One would think of DP but size of X = 10^14 makes things tricky.