Q2) part A logic. N = 6, K = 8. K = 8 means next four trains can enter in any order they like after which the last train must leave the yard. In any order because it doesn’t matter when they enter and leave each action costs 1 K and 4 trains entering and leaving will cost us 8 K. Now here are all the cases.Will will consider 6 fixed in all possible positions.

```
1*6*2345 ]- 2345 can be in any order so 4! = 24
12*6*345 ]- 345 and 12 can be in any order so 3!*2! = 12
123*6*45 ]- 45 and 123 can be in any order so 3!*2! = 12
1234*6*5 ]- 1234 can be in any order so 4! = 24
12345*6* ] - 12345 can be in any order so 5! = 120
```

24 + 12 + 12 + 24 + 120 = 192.

I tried to do part B with this method but it was very time consuming so I left it. I didn’t try C because I had given up.

EDIT: EXPLANATION.

What I have done is fixed the number 6 in the output place to a particular digit, then I am moving around whatever numbers I can to take a look at permutations. For instance in first line I say 2345 can be in any order. 2345, 5324, and so on can be created without hassle. I have taken its factorial. For those who don’t know what a factorial is google it and read about permutations.

@superty Because we are having trouble with deciding the correct solution I suggest we both make a text file of our possible cases and then we can see the subset of non-intersecting cases and decide.

EDIT: THIS IS WRONG, This logic generates cases which are not possible.