Subin is sitting on the coordinate plane. "I love the coordinate plane so much!!" said Subin. The plane has N candy baskets, and each basket holds M candies. The baskets are at (x1,y1),(x2,y2),…,(xN,yN), and Subin starts at (0,0).
The weather is hot today. Each time 1 unit of time passes, one candy melts away from every basket that still has candy left. After t units of time have passed, a basket holds max(0,M−t) candies.
Subin is very hungry, so when he reaches a basket he eats all the candies in it instantly. Eating takes no time. When Subin moves a distance of 1, 1 unit of time passes. Subin can move only up (the direction in which the y coordinate increases) or right (the direction in which the x coordinate increases).
Write a program that finds the maximum number of candies Subin can eat.