use <algorithm> instead of #define MAX