AnyDice — efficiency of code calculating rolls hitting a target with mixed pools; hitting the 5 second barrier

I have some code that is hitting the 5 second barrier;

function: target N:n of A:s B:s C:s {     result: [count {1..N, 1..(N/2)} in [sort {A, B, C}]] } output [target 7 of 4d12 0d20 0d8] output [target 7 of 4d12 2d20 0d8] output [target 7 of 4d12 4d20 0d8] 

Even if I remove the final output line, it still fails.

I believe the code does what I want it to – calculate the number of dice rolling at or under the target from mixed pools (it runs when using other pools: d20s seem to be a problem).

Is there anyway I can improve it so that at least the first two of these output lines will run (or better yet, all three of them)?

N.b. from my perspective these were some of the simplest pools I wanted to look at.