Buggy python submission (verdict: Runtime Error):
import sys


def main():
    N, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split())) * K

    count = 0

    for i in range(K * N - 1):
        for j in range(i + 1, N * K):
            if A[i] > A[j]:
                count = count + 1

    ans = count % 1000000007
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
import sys


def main():
    N, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))

    count1 = 0
    count2 = 0

    for i in range(N - 1):
        for j in range(i + 1, N):
            if A[i] > A[j]:
                count1 = count1 + 1
            if A[i] != A[j]:
                count2 = count2 + 1
    count1 = count1 * K
    count2 = count2 * (K * (K - 1) // 2)

    ans = (count1 + count2) % 1000000007
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys


def main():
    N, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split())) * K

    tree = [0] * (K * N + 1)
    count = 0

    for i in A:
        tree[i] = tree[i] + 1
        count = count + sum(tree[i + 1 :])

    ans = count % (10 ** 9 + 7)
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
import sys


def main():
    N, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))

    count1 = 0
    count2 = 0

    for i in range(N - 1):
        for j in range(i + 1, N):
            if A[i] > A[j]:
                count1 = count1 + 1
            if A[i] != A[j]:
                count2 = count2 + 1
    count1 = count1 * K
    count2 = count2 * (K * (K - 1) // 2)

    ans = (count1 + count2) % 1000000007
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys


def main():
    N, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split())) * K

    count = 0

    for i, n in enumerate(A):
        for j, m in enumerate(A):
            if i <= j:
                break
            elif m > n:
                count = count + 1

    ans = count % (10 ** 9 + 7)
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
import sys


def main():
    N, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))

    count1 = 0
    count2 = 0

    for i in range(N - 1):
        for j in range(i + 1, N):
            if A[i] > A[j]:
                count1 = count1 + 1
            if A[i] != A[j]:
                count2 = count2 + 1
    count1 = count1 * K
    count2 = count2 * (K * (K - 1) // 2)

    ans = (count1 + count2) % 1000000007
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split())) * K


def main():
    count = 0
    for i in range(0, K * N - 1):
        for j in range(1, K * N):
            if i < j and A[i] > A[j]:
                count = count + 1

    ans = count % (10 ** 9 + 7)
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
import sys


def main():
    N, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))

    count1 = 0
    count2 = 0

    for i in range(N - 1):
        for j in range(i + 1, N):
            if A[i] > A[j]:
                count1 = count1 + 1
            if A[i] != A[j]:
                count2 = count2 + 1
    count1 = count1 * K
    count2 = count2 * (K * (K - 1) // 2)

    ans = (count1 + count2) % 1000000007
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split())) * K

count = 0

for i in range(0, K * N - 1):
    for j in range(1, K * N):
        if i < j and A[i] > A[j]:
            count = count + 1

ans = count % (10 ** 9 + 7)
print(ans)

Fixed submission:
import sys


def main():
    N, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))

    count1 = 0
    count2 = 0

    for i in range(N - 1):
        for j in range(i + 1, N):
            if A[i] > A[j]:
                count1 = count1 + 1
            if A[i] != A[j]:
                count2 = count2 + 1
    count1 = count1 * K
    count2 = count2 * (K * (K - 1) // 2)

    ans = (count1 + count2) % 1000000007
    print(ans)


if __name__ == "__main__":
    main()