Here are three ways to solve the problem, just change the letters. The third solution is simple and clear.
Solution 1
Solution 2
Solution 3