Lets see if I can help (I am weak in PnC, but lets see…)

firstly, what you wrote- " 2fact[n-2]-6fact[n-3] or 2(n-5)fact[n-5]?? "

Is this answer for ALL cases, even when n<=5? No. Special cases must be considered. (cause 2 *(5-2)! - 6*(5-3)! = 2*6 - 6*2=0 and at n=3, its 2*(3-2)! -6*(3-3)! = 2-6 = negative!!)

Well, its obvious that for n=3, and n=4, the answer is 0.

At n=5, lets try placing. (H=Harsh, R=Rahul, G=Girl, B1,B2 etc = Other boys)

B1 G H B2 R

(imagine it in circular order, end connected to front)

So there is a boy b/w harsh and Rahul and girl and Rahul. We can interchange position of harsh and girl, and/or the two boys and that order would be still acceptable. In other words, there are two ways to place Harsh and Girl (we can interchange them: meaning, the “G H” in above could be “H G”) and 2 ways to place boys. (Interchanging boys)

Ans = 2*2 =4.

Now speaking of general n.

The answer is 2fact[n-2]-6fact[n-3]

What I can think of-

Consider girl and Harsh to be a single block. Now we have to arrange (n-2+1) = (n-1) people, which could be done in (n-2)! ways. And since harsh and Girl can interchange position, total permutations are 2*(n-2)!

Now considering Rahul in picture. We include Rahul in the block. Now, we have to arrange (n-3+1)=n-2 people, which can be done in (n-3)! ways. and this block could re-arrange in 3! ways. So 6*(n-3)! (Yeah…I think it considers arrangement GRH [Rahul between Girl and Harsh - Harsh NOT beside Girl] in this…That’s all I could come up with after 2 hours of brainstorming…I think this thing is cancelling out the repetitions occurring symmetrically…either this or it has something to do with things %(10000007).

Because what I would have come up with by my own instincts, would be 2(n-2)! - 4(n-3)! , meaning disregarding position of Rahul in between G and H]

EDIT x3- AS MEOW SAID, THE TEST CASES ARE INCORRECT. WHAT YOU THOUGHT IS THE RIGHT ANSWER. The accepted answer HAS TO AND MUST ACCEPT possibility of Rahul in between Harsh and Girl. Without which, it cannot justify the 6 in “-6*(n-3)!”

What actually amazes me is that so many people actually SOLVED AND GOT AWAY with the problem. The test case doesn’t check at critical n of 5, where many people gave 0 and got away. It seriously needs to be seen!!

(I am sorry, I cant help any further. Finding how many things instances are repeating is a bit too tough for me. I already spent 2 hours on this answer XD)

EDIT 2-

Okay, I saw the codes which passed all test cases and was shocked to see this-

```
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int t, n, p[1001001];
int main() {
// freopen("c.in", "r", stdin);
p[1] = 1;
for (int i = 2; i <= 1000000; i ++) p[i] = 1ll * p[i-1] * i % mod;
scanf("%d", &t);
while (t --) {
scanf("%d", &n);
printf("%d\n", n <= 5 ? 0 : 2ll * (n - 5) * p[n-3] % mod);
}
return 0;
}
```

Specifically “printf(”%d\n", n <= 5 ? 0 : 2ll * (n - 5) * p[n-3] % mod);"

At n=5, this gave ans of 0 and was accepted!! Weak test cases? Can somebody throw some light here? (I am genuinely confused)