implement calculation with max three variables