A kingdom has N people. The amount of money each person holds is a non-negative integer, and the people are numbered 1 through N.
One day the king proclaimed a decree. The money any person holds may differ from the money each of that person's friends holds by at most d. In other words, for a person to hold x, none of that person's friends may hold less than x−d and none may hold more than x+d.
Among all distributions that obey the decree, the people want the one where the gap between the richest person and the poorest person is as large as possible.
Given the number of people and the friendships, write a program that computes the largest possible gap.