outpit min and max valve, change calculte sum in code