Hello everyone!

I need help with the following problem. In the column A, I have 4 different values. I need a formula that will count the number of appearances of the value 0 since the last time the value 39 has appeared. Values 19 and 20 are not important, but they have to be there. Basically it counts the number of times the lowest value in the column A has appeared since the last appearance of the greatest value in the same column. The formula will be put in column B and will have to show the results below.
Is it possible?
Thanks in advance!

Column A
39
19
20
0
20
19
19
19
0
39
19
0
39
19
39
0
0
0
19
39
20
0
20


Column B
0
0
0
1
1
1
1
1
2
0
0
1
0
0
0
1
2
3
3
0
0
1
1