This is a tricky question. The native ear will immediately recognize that "had been remained" is not correct. The had should be followed by a past participle. Remained and been are both past participles; you can use one or the other, but not both.
So, either of these could be used to start the sentence:
- He had been president for 20 years...
- He had remained president for 20 years...
This issue gets tricky, however, when you switch to the passive voice. In that case, you can use he had been followed by a past participle, as in:
- He had been elected 20 years ago...
That's a valid formation, and it's listed as the past perfect passive verb form in this table1:
So, the question becomes, why can the verb elected be used in this way, but not the verb remained?
The key is that the sentence with elected is using the passive construction, but the sentence with remained has an active construction. As Dave Sperling says on his ESL website:
Because subjects of passive verbs receive the action, verbs that cannot have objects (intransitive verbs) do not have passive forms.
If you look up the words in a dictionary, you'll see that elect is transitive, and remain is intransitive, which is why had been remained sounds so awkward to the native ear, while had been elected sounds just fine – although many native speakers might have a hard time explaining why.
Now, you can explain it for them: "It's because remained is an intransitive verb, so it cannot be used in the passive voice."
Although I know that I can't elaborate the issues well, I would like to point out a few important grammar terms related to the constructions (A) and (B) in the OP's question. Most of the following is extracted from Practical English Usage by Michael Swan. Some is extracted from Wikipedia pages. Mistakes are mine.
Present Perfect: We use present perfect to say that a finished action or event is connected with the present in some way. If we say that something has happened, we are thinking about the past and the present at the same time. (For example, I have known her for years. You have done a lot for me.)
Passive Voice (also known as "Passives"): In a clause with passive voice, the subject denotes the recipient of the action rather than the performer. (They built this house, is in active voice. The house was built, is in passive voice.) Passive tenses are normally used in the same way as active tenses. For example, the present progressive passive is used, like the present progressive active, to talk about things that are going on at the time of speaking. (For example, The papers are being prepared now.)
Gerunds: When -ing forms are used like nouns, they are often called "gerunds". (For example, Smoking is bad for you. I hate packing suitcases.) It can sometimes be difficult to decide which term to use (between "gerunds" and "present participles"). Some grammar books might refer to verbs with -ing as "-ing forms".
Both OP's sentences (A) and (B) are in the past tense. They both have the same main verb, liked.
Consider sentence (A),
She liked being looked at.
The part "being looked" is a gerund, as godel9 explained.
Now, consider sentence (B),
She liked having been looked at.
The part "having been looked" in sentence (B) is also a gerund. It is also in a perfect tense, and in passive voice. Although this construction is possible, it's rare. The COCA corpus returned no result at all for other verbs in the place of liked, except for reported. For example,
Most patients reported having been bitten or scratched by an animal.
Less than one in four IDUs surveyed reported having been offered vaccination ...
Best Answer
If you are writing a letter, and you missed a single class, use:
If you missed a series of classes, and you have not been back to class yet, and you want to allude to the ongoing practice of missing class, use:
That second sentence might be better if you were unable to attend class for a more prolonged period of time. It sounds like the wording you might have been fishing for.