Fully three-dimensional ideal magnetohydrodynamic stability analysis of low- n modes and Mercier modes in stellarators