Formula(s) needed

For the table below, I need a formula (or two formulas) for E2 and E5:

check-formula

E2 should read “CHECK” if A2 is “ABC” and C1=C2 and D1=D2.
E5 should read “CHECK” if A5 is “DEF” and C4≠C5.

Here “string” stands for 0 or more characters, “word” stands for 1 or more characters. Cells in column B may have 0 or more characters each.

check-formula.ods (9.3 KB)

How can I achieve this?

LO 24.2.1.2

Hallo
E2 ⇒

=IF(OR(AND(A2="ABC";C1=C2;D1=D2);AND(A2="DEF";C1<>C2));"CHECK";"")

pull down!