The invention relates to novel heterocyclic compounds of the formula in which all of the variables are as defined in the specification, pharmaceutical compositions thereof, combinations thereof, and their use as medicaments, particularly for the treatment of Alzheimers Disease or diabetes via inhibition of BACE-1 or BACE-2.