Modify arithmetic mean to prevent overflows when handling large numbers