Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9 + 7

LANK = list(set(A))
LANK.sort()
LANK2 = [0] * 2000
for i, l in enumerate(LANK):
    LANK2[l] = i

LANK = [-1] * N
for i,a in enumerate(A):
    LANK[i] = LANK2[a]

back = [0] * N
for i,a in enumerate(A[::-1]):
    cnt = 0
    for j,a2 in enumerate(A[::-1]):
        if i > j and a > a2:
            cnt += 1
    back[N-1-i] = cnt
    
SUM = 0
tmp = K*(K-1) //2
tmp %= MOD

for i,a in enumerate(A):
    SUM += (LANK[i] * tmp)%MOD
    SUM += (back[i] * K)%MOD
    SUM %= MOD
print(SUM)

Fixed submission:
N, k = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

ans = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            if i > j:
                ans += k*(k-1)//2
            elif i < j:
                ans += k*(k+1)//2
            ans %= MOD

print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9 + 7

LANK = list(set(A))
LANK.sort()
LANK2 = [0] * 2000
for i, l in enumerate(LANK):
    LANK2[l] = i

LANK = [-1] * N
for i,a in enumerate(A):
    LANK[i] = LANK2[a]

back = [0] * N
for i,a in enumerate(A[::-1]):
    cnt = 0
    for j,a2 in enumerate(A[::-1]):
        if i > j and a > a2:
            cnt += 1
    back[N-1-i] = cnt
    
SUM = 0
tmp = K(K-1)//2
tmp %= MOD
# print('a')
for i,a in enumerate(A):
    SUM += (LANK[i] * tmp)%MOD
    SUM += (back[i] * K)%MOD
    SUM %= MOD
print(SUM)

Fixed submission:
N, k = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

ans = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            if i > j:
                ans += k*(k-1)//2
            elif i < j:
                ans += k*(k+1)//2
            ans %= MOD

print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9 + 7

LANK = list(set(A))
LANK.sort()
LANK2 = [0] * 2000
for i, l in enumerate(LANK):
    LANK2[l] = i

LANK = [-1] * N
for i,a in enumerate(A):
    LANK[i] = LANK2[a]

back = [0] * N
for i,a in enumerate(A[::-1]):
    cnt = 0
    for j,a2 in enumerate(A[::-1]):
        if i > j and a > a2:
            cnt += 1
    back[N-1-i] = cnt
    

SUM = 0
tmp = sum(range((K)))
for i,a in enumerate(A):
    SUM += LANK[i] * tmp + back[i] * K
    SUM %= MOD
print(SUM)

Fixed submission:
N, k = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

ans = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            if i > j:
                ans += k*(k-1)//2
            elif i < j:
                ans += k*(k+1)//2
            ans %= MOD

print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9 + 7

LANK = list(set(A))
LANK.sort()
print(LANK)
LANK2 = [0] * 2000
for i, l in enumerate(LANK):
    LANK2[l] = i

LANK = [-1] * N
for i,a in enumerate(A):
    LANK[i] = LANK2[a]

back = [0] * N
for i,a in enumerate(A[::-1]):
    cnt = 0
    for j,a2 in enumerate(A[::-1]):
        if i > j and a > a2:
            cnt += 1
    back[N-1-i] = cnt
    

SUM = 0
tmp = sum(range((K)))
for i,a in enumerate(A):
    SUM += LANK[i] * tmp + back[i] * K
    SUM %= MOD
print(SUM)

Fixed submission:
N, k = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

ans = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            if i > j:
                ans += k*(k-1)//2
            elif i < j:
                ans += k*(k+1)//2
            ans %= MOD

print(ans)