Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define L_T_S_K ;
const int mod = 1e9 + 7;
int binpow(int a, int b) {
    a %= mod;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
int mul(int a , int b){
   return ((a % mod) * (b % mod )) % mod; 
} 
int divi(int a, int b){
    return(mul(a, binpow(b, mod - 2)) % mod);
}
int32_t main(){
 L_T_S_K;
    int n , k;
    cin >> n >> k;
    int a[n];
    for(int i = 0 ; i < n ; i++){
        cin >> a[i];
    }
    int inv[n] ,ans = 0;
    for(int i = 0 ; i < n ; i++){
        int cnt = 0;
        for(int j = i + 1 ; j < n ; j++){
            cnt+=(a[i] > a[j]);
        }
        inv[i] = cnt;
       // ans= ( ans % mod + cnt % mod)%mod;
    }
    int small[n] = {};
    for(int i = n - 1 ; i >= 0 ; i-- ){
        int cnt = 0;
        for(int j = i - 1 ; j >= 0 ; j--){
            cnt+=(a[i] > a[j]);
        }
        small[i] = cnt;
    }
    for(int i = 0 ; i < n ; i++){
        int r = ( ( inv[i] % mod + small[i] % mod) % mod );
        int t = ( mul(k , inv[i]) + divi( mul( mul(k , k - 1) , r ) , 2) ) % mod; 
        ans = ( ans % mod + t % mod)%mod;
    }   
    cout << ans << " ";
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define L_T_S_K ;
const int mod = 1e9 + 7;
int binpow(int a, int b) {
    a %= mod;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
int mul(int a , int b){
   return ((a % mod) * (b % mod )) % mod; 
} 
int divi(int a, int b){
    return(mul(a, binpow(b, mod - 2)) % mod);
}
int32_t main(){
 L_T_S_K;
    int n , k;
    cin >> n >> k;
    int a[n];
    for(int i = 0 ; i < n ; i++){
        cin >> a[i];
    }
    int inv[n] ,ans = 0;
    for(int i = 0 ; i < n ; i++){
        int cnt = 0;
        for(int j = i + 1 ; j < n ; j++){
            cnt+=(a[i] > a[j]);
        }
        inv[i] = cnt;
       // ans= ( ans % mod + cnt % mod)%mod;
    }
    int small[n] = {};
    for(int i = n - 1 ; i >= 0 ; i-- ){
        int cnt = 0;
        for(int j = i - 1 ; j >= 0 ; j--){
            cnt+=(a[i] > a[j]);
        }
        small[i] = cnt;
    }
    for(int i = 0 ; i < n ; i++){
        int r = ( ( inv[i] % mod + small[i] % mod) % mod );
        int t = ( mul(k , inv[i]) + divi( mul( mul(k , k - 1) , r ) , 2) ) % mod; 
        ans = ( ans % mod + t % mod)%mod;
    }   
    cout << ans << " ";
 return 0;
}




Compiler output:
a.cc:62:11: error: redefinition of 'const long long int mod'
   62 | const int mod = 1e9 + 7;
      |           ^~~
a.cc:5:11: note: 'const long long int mod' previously defined here
    5 | const int mod = 1e9 + 7;
      |           ^~~
a.cc:63:5: error: redefinition of 'long long int binpow(long long int, long long int)'
   63 | int binpow(int a, int b) {
      |     ^~~~~~
a.cc:6:5: note: 'long long int binpow(long long int, long long int)' previously defined here
    6 | int binpow(int a, int b) {
      |     ^~~~~~
a.cc:74:5: error: redefinition of 'long long int mul(long long int, long long int)'
   74 | int mul(int a , int b){
      |     ^~~
a.cc:17:5: note: 'long long int mul(long long int, long long int)' previously defined here
   17 | int mul(int a , int b){
      |     ^~~
a.cc:77:5: error: redefinition of 'long long int divi(long long int, long long int)'
   77 | int divi(int a, int b){
      |     ^~~~
a.cc:20:5: note: 'long long int divi(long long int, long long int)' previously defined here
   20 | int divi(int a, int b){
      |     ^~~~
a.cc:80:9: error: redefinition of 'int32_t main()'
   80 | int32_t main(){
      |         ^~~~
a.cc:23:9: note: 'int32_t main()' previously defined here
   23 | int32_t main(){
      |         ^~~~