Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
#include<algorithm>
#define intt long long
const intt NUM = 1000000007;

int main(){
	intt N{}, K{}, initi{}, initi2{}; std::cin >> N >> K;
	std::vector<intt> A(N); for (auto& r : A) { std::cin >> r; }
	for (intt i = 0; i < N - 1; ++i) for (intt j = i + 1; i < N; ++i) if (A[i] > A[j]) {++initi; initi %= NUM;}
	for (intt i = 0; i < N; ++i) for (intt j = 0; j < N; ++j) if (A[i] > A[j]) { ++initi2; initi2 %= NUM; }
	std::cout << ((((initi % NUM) * K) % NUM) + ((initi2 % NUM) * (((K * (K - 1)) % NUM) / 2) ) % NUM)<< std::endl;
	return 0;
}

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
total_1 = 0
for i in range (n - 1):
    for j in range (i + 1, n):
        if a[i] > a[j]:
            total_1 += 1
total_2 = 0
for i in range (n):
    for j in range (n):
        if a[i] > a[j]:
            total_2 += 1
print((total_1 * k + (total_2 * k * (k - 1)) // 2) % (10 ** 9 + 7))

Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
#include<algorithm>
#define intt long long
const intt NUM = 1000000007;

int main(){
	intt N, K, initi, initi2{}; std::cin >> N >> K;
	std::vector<intt> A(N); for (auto& r : A) { std::cin >> r; }
	for (intt i = 0; i < N - 1; ++i) for (intt j = i + 1; i < N; ++i) if (A[i] > A[j]) {++initi; initi %= NUM;}
	for (intt i = 0; i < N; ++i) for (intt j = 0; j < N; ++j) if (A[i] > A[j]) { ++initi2; initi2 %= NUM; }
	std::cout << ((((initi % NUM) * K) % NUM) + ((initi2 % NUM) * (((K * (K - 1)) % NUM) / 2) ) % NUM)<< std::endl;
	return 0;
}

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
total_1 = 0
for i in range (n - 1):
    for j in range (i + 1, n):
        if a[i] > a[j]:
            total_1 += 1
total_2 = 0
for i in range (n):
    for j in range (n):
        if a[i] > a[j]:
            total_2 += 1
print((total_1 * k + (total_2 * k * (k - 1)) // 2) % (10 ** 9 + 7))

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
total_1 = 0
for i in range (n - 1):
    for j in range (i + 1, n):
        if a[i] > a[j]:
            total_1 += 1
total_2 = 0
for i in range (n):
    for j in range (n):
        if a[i] > a[j]:
            total_2 += 1
print((total_1 * k + (total_2 * k * (k - 1)) // 2) % (10 ** 9 + 7)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
total_1 = 0
for i in range (n - 1):
    for j in range (i + 1, n):
        if a[i] > a[j]:
            total_1 += 1
total_2 = 0
for i in range (n):
    for j in range (n):
        if a[i] > a[j]:
            total_2 += 1
print((total_1 * k + (total_2 * k * (k - 1)) // 2) % (10 ** 9 + 7))

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
total_1 = 0
for i in range (n - 1):
    for j in range (i, n):
        if a[i] > a[j]:
            total_1 += 1
total_2 = 0
for i in range (n):
    for j in range (i):
        if a[i] > a[j]:
            total_2 += 1
def factorial(n):
    total = 0
    while(n > 0):
        total += n
        n -= 1
    return total

print(total_1 * K + total_2 * factorial(K - 1))

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
total_1 = 0
for i in range (n - 1):
    for j in range (i + 1, n):
        if a[i] > a[j]:
            total_1 += 1
total_2 = 0
for i in range (n):
    for j in range (n):
        if a[i] > a[j]:
            total_2 += 1
print((total_1 * k + (total_2 * k * (k - 1)) // 2) % (10 ** 9 + 7))