How many different identifiers can a fictitious programming language have? How many different identifiers can a fictitious programming language have, when the following rules must be obeyed:

*

*Only upper case letters are allowed, so elements of $\{A, ..., Z\}$,

*The identifier must be at least of length $1$ and at most length $5$.

*The keywords AND, OR, IF, THEN and GOTO are not allowed to appear in any form in the identifier.

I approached this by looking at the allowed lengths individually and then add all the combinations up.
Length = 1:
Here we simply have only $26$ possibilities.
Length = 2:
This time we have $26^2 - 2$ combinations, since IF and OR can't appear.
Length = 3:
This one is also quite simple. We have $25^3 - 1 - 2*26 - 2*26$ combinations, since AND is not allowed to appear and all combinations that contain IF (IF. and .IF) or OR (OR. and .OR) are invalid.
Length = 4:
This is where I start to have my problems. I tried to do the same thing here, but I am not quite sure. There are $26^4$ total combinations. This time THEN and GOTO can't appear, so $-2$ to accommodate this. AND also can't appear, so $-2*26$. But for IF and OR I am not certain how to calculate it. At first I thought it would simply be $-3*26^2 - 3*26^2$ (IF.. , .IF. , ..IF , OR.. , .OR. , ..OR), but then I thought this would count certain combinations more than once. The combination IFOR for example would be counted twice, so I would have to add $1$ to make up for that. Then there are the combinations IFIF and OROR, which also would be subtracted twice so I would have to add $+1+1$ again. And I am not sure if I missed some of these.
So for Length > 3 I am not quite sure how to tackle this, so I don't miss any combinations and everyone is counted only once.
 A: For $n=4$, you also need to add back in IFOR and ORIF. In other words, all of the doubly subtracted codes look like
$$
AABB, 
$$
where $AA$ and $BB$ are both bad words of length $2$. There are two choices for $AA$, and two choices for $BB$, so you need to add back in $2\times 2$.
When $n=5$, there are more possibilities for doubly subtracted words: they can be
$$
AABB*,\quad AA{*}BB,\quad*AABB,\\
AACCC,\quad CCCAA
$$
Again, $AA$ and $BB$ are arbitrary two-letter bad words, and $CCC$ is an arbitrary three letter bad word (okay, there is only one possibility for $CCC$, but I am trying to show how this will generalize).
That seems to be all the ways to cram two of the bad words into a five letter string. But these are only the ways where the two words do not overlap. Since the end of GOTO is the same as the beginning of OR, there is one final doubly subtracted word, namely,
$$
GOTOR.
$$
You can check this is the only possibility for overlap. In general, if you had lots of overlapping possibilities, things would be more more complicated. Furthermore, if $n\ge 6$, you would have to worry about triply subtracted words, like IFOROR. This problem, however, is quite tractable.
In summary, you initially subtract the words which contain each possible bad word in each possible position, not worrying about double counting, resulting in $$26^5-4\cdot 26^3-4\cdot 26^3-3\cdot 26^2-2\cdot 26-2\cdot 26.$$ But then you must add in all of the doubly subtracted words in the previous paragraphs. For example, for words like $AABB*$, you would add back in $2\times 2\times 26$. I will see you if can finish the rest.
This type of counting is called the inclusion exclusion principle, or in and out method.
