Multiple switch state coding help

Where do you ever set Relay_Bn LOW again? Are the Relay_Bn relays also constrained to have no more than 2 HIGH at a time?

Where are the Serial.print(ln) statements?

    if (val1 + val2 + val3 + val4 + val5 <= 2)

Wouldn't it be better to simply add all 5 values once, and compare the sum? Is this even necessary? Shouldn't total reflect the number of A relays that should be set HIGH (if there were enough of them to go around)?