Help in using MOD operator

I need to calculate (n^2-3n)/2 for n upto 10^18 .If the value becomes larger then I have to take MOD with 10^9 + 7 .I am trying to do (((n%MOD)**(n%MOD))%MOD-(3(n%MOD))%MOD)/2 but its giving me WA…

If you divide an odd number by 2 modulo 10^9+7, you need to add 10^9+7 to the number first to get an even number that is the same (mod 10^9 +7). Calculated this way, (3 / 2) mod (10^9 + 7) equals 500000005. This is correct, because (2 * 500000005) mod (10^9 +7) equals 3 .

If it is possible to calculate (n^2-3n)/2 precisely and then apply the mod operator, you can do that, because (n^2-3n) is always even. (n^2-3n) mod (10^9 + 7) is not always even.

//