Use If flexibly to get average


I want to calculate the response time across multiple subjects with one restriction: only response time from the correct trials should be included in the average. The structure of my data looks like below (for simplicity, I show only 3 subjects and 10 trials, in reality, I have many more)


I would like to get average of RT across subj1, subj2, and subj2 for each of the trials. Only correct trials are included in the average. 0 and 1 are used to denote incorrect and correct trials, respectively. For instance, for cell G2, I would only include B2 and D2 in the average, F2 is left out since the ACC for that trial from that subject is 0. I imagined using If AND function to include the appropriate RT but with many subjects, this becomes very clumsy. Does anyone have a clever solution to this?