=LET( s, A2:A13, r, C2:C13, SCAN(0, SEQUENCE(ROWS(s)), LAMBDA(a, v, IF(INDEX(VSTACK("Y", r), v) = "Y", a * 0 + INDEX(s, v), a + INDEX(s, v)))) )