I am having a little trouble working out how to calculate a few things in R studio

How would I go about calculating the probability of an event occurring successfully a set number of times but then not occurring? For example, if the sample size was 20 and the probability like 0.4 how could I calculate the probability that only the first X number are successful and the rest are failures. This does refer to binomial cases where the result is like Head/Tails or Pass/fail on test.

Another thing I am struggling with is how to calculate the 25th, 75th percentiles and interquartile range when given mean and standard deviation.

The final thing I'm trying to work out is how to combine the probabilities of two events. For example, how do I combine the probability of say the first 3 events of the sample being successful with the probability of 3 events being successful out of the remaining 10.

Another case of combining which I am struggling with is calculating the probability of a certain number of random samples being within a range. I can calculate the probability of a single sample being within the range but unsure how to take that and combine to say find out the probability that 4 out of 15 are within that range.

Would love any help I can get.