Problem:


Score : 300 points

Problem Statement

We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.

Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.

Find the inversion number of B, modulo 10^9 + 7.

Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that  B_i > B_j.

Constraints

All values in input are integers.

1 \leq N \leq 2000

1 \leq K \leq 10^9

1 \leq A_i \leq 2000

Input

Input is given from Standard Input in the following format:

N K
A_0 A_1 ... A_{N - 1}

Output

Print the inversion number of B, modulo 10^9 + 7.

Sample Input 1

2 2
2 1

Sample Output 1

3

In this case, B~=~2,~1,~2,~1. We have:

B_0 > B_1

B_0 > B_3

B_2 > B_3

Thus, the inversion number of B is 3.

Sample Input 2

3 5
1 1 1

Sample Output 2

0

A may contain multiple occurrences of the same number.

Sample Input 3

10 998244353
10 9 8 7 5 6 3 4 2 1

Sample Output 3

185297239

Be sure to print the output modulo 10^9 + 7.



Sample input:
2 2
2 1


Sample output:
3

Submission status: Wrong Answer

Solution code:
def main(n,k,a):

    mod = 10**9 + 7
    t1, t2 = 0, 0
    for i in range(n):
        for j in range(n):
            if a[i] > a[j]:
                t1 += 1
        for j in range(n - i - 1):
            if a[i] > a[j + i + 1]:
                t2 += 1

    count = (t1 * ((k * (k - 1)) / 2)) % mod
    count += (t2 * k) % mod
    print(int(count % mod))


if __name__ == '__main__':
    n, k = map(int, input().split(' '))
    a = list(map(int, input().split(' ')))
    main(n,k,a)

Submission status: Wrong Answer

Solution code:
def main(n,k,a):

    mod = 10**9 + 7
    t1, t2 = 0, 0
    for i in range(n):
        for j in range(n):
            if a[i] > a[j]:
                t1 += 1
        for j in range(n - i - 1):
            if a[i] > a[j + i + 1]:
                t2 += 1

    count = t1 * ((k * (k - 1)) / 2) % mod
    count += (t2 * k) % mod
    print(int(count % mod))


if __name__ == '__main__':
    n, k = map(int, input().split(' '))
    a = list(map(int, input().split(' ')))
    main(n,k,a)

Submission status: Wrong Answer

Solution code:
def main(n,k,a):

    mod = 10**9 + 7
    t1, t2 = 0, 0
    for i in range(n):
        for j in range(n):
            if a[i] > a[j]:
                t1 += 1
        for j in range(n - i):
            if a[i] > a[j + i]:
                t2 += 1

    count = t1 * ((k * (k - 1)) / 2) % mod
    count += (t2 * k) % mod
    print(int(count % mod))


if __name__ == '__main__':
    n, k = map(int, input().split(' '))
    a = list(map(int, input().split(' ')))
    main(n,k,a)

Submission status: Wrong Answer

Solution code:
def main(n,k,a):

    mod = 10**9 + 7
    t1, t2 = 0, 0
    for i in range(n):
        for j in range(n):
            if a[i] > a[j]:
                t1 += 1
        for j in range(n - i):
            if a[i] > a[j + i]:
                t2 += 1

    # count = ((t1 * k) % mod * (k - 1)) % mod / 2 % mod
    # count += t2 * k % mod
    count = (t1*k*(k-1)/2%mod + t2*k)%mod
    print(int(count))


if __name__ == '__main__':
    n, k = map(int, input().split(' '))
    a = list(map(int, input().split(' ')))
    main(n,k,a)

Submission status: Wrong Answer

Solution code:
def main(n,k,a):

    mod = 10**9 + 7
    t1, t2 = 0, 0
    for i in range(n):
        for j in range(n):
            if a[i] > a[j]:
                t1 += 1
        for j in range(n - i):
            if a[i] > a[j + i]:
                t2 += 1

    count = ((t1 * k) % mod * (k - 1))  % mod / 2 % mod
    count += t2 * k % mod
    print(int(count % mod))


if __name__ == '__main__':
    n, k = map(int, input().split(' '))
    a = list(map(int, input().split(' ')))
    main(n,k,a)

Submission status: Wrong Answer

Solution code:
def main(n,k,a):

    mod = 10**9 + 7
    t1, t2 = 0, 0
    for i in range(n):
        for j in range(n):
            if a[i] > a[j]:
                t1 += 1
        for j in range(n - i):
            if a[i] > a[j + i]:
                t2 += 1
                
    count = t1 * k * (k - 1) / 2 % mod
    count += t2 * k % mod
    print(int(count % mod))


if __name__ == '__main__':
    n,k = map(int, input().split(' '))
    a = list(map(int, input().split(' ')))
    main(n,k,a)

Submission status: Wrong Answer

Solution code:
def main(n,k,a):

    mod = 10**9 + 7
    t1, t2 = 0, 0
    for i in range(n):
        for j in range(n):
            if a[i] > a[j]:
                t1 += 1
        for j in range(n - i):
            if a[i] > a[j + i]:
                t2 += 1
        count = t1 * k * (k - 1) / 2 % mod
        count += t2 * k % mod

    print(int(count % mod))


if __name__ == '__main__':
    n,k = map(int, input().split(' '))
    a = list(map(int, input().split(' ')))
    main(n,k,a)

Submission status: Wrong Answer

Solution code:
def main(n,k,a):

    mod = 10**9 + 7
    t1, t2 = 0, 0
    for i in range(n):
        for j in range(n):
            if a[i] > a[j]:
                t1 += 1
        for j in range(n - i):
            if a[i] > a[j + i]:
                t2 += 1
        count = t1 * k * (k - 1) / 2 % mod
        count += t2 * k % mod

    print(t1, t2)

    print(int(count % mod))


if __name__ == '__main__':
    n,k = map(int, input().split(' '))
    a = list(map(int, input().split(' ')))
    main(n,k,a)

Submission status: Wrong Answer

Solution code:
# jsc2019-qualB - Kleene Inversion
from collections import Counter
from itertools import accumulate


def main():
    N, K = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))
    MOD = 10 ** 9 + 7
    C = list(Counter(A).values())
    x = sum(list(accumulate(C[:-1]))) % MOD
    y = 0
    for i, a in enumerate(A[:-1]):
        y += sum(b > a for b in A[i + 1 :])
    ans = (x * (1 + K) * K // 2) % MOD
    ans -= y * K
    ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
k = k % mod
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            elif i < j:
                b[i][1] += 1
    b[i][0] = b[i][0] % mod
    b[i][1] = b[i][1] % mod
ans = 0
# kまでの和　後ろの数用
sigmakp = (int(((k * (k+1)) % mod) / 2)) % mod
# k-1までの和　前の数用
sigmakn = (int(((k * (k-1)) % mod) / 2)) % mod

for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
k = k % mod
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            elif i < j:
                b[i][1] += 1
    b[i][0] = b[i][0] % mod
    b[i][1] = b[i][1] % mod
ans = 0
# kまでの和　後ろの数用
sigmakp = (((k * (k+1)) % mod) / 2) % mod
#sigmakp = int(sigmakp)
# k-1までの和　前の数用
sigmakn = (((k * (k-1)) % mod) / 2) % mod
#sigmakn = int(sigmakn)

for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(int(ans))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
k = k % mod
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            elif i < j:
                b[i][1] += 1
    b[i][0] = b[i][0] % mod
    b[i][1] = b[i][1] % mod
ans = 0
# kまでの和　後ろの数用
sigmakp = (((k * (k+1)) % mod) / 2) % mod
#sigmakp = int(sigmakp)
# k-1までの和　前の数用
sigmakn = (((k * (k-1)) % mod) / 2) % mod
#sigmakn = int(sigmakn)

for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
 
mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j  in range(i,n):
        if a[i] > a[j]:
                b[i][1] += 1
        elif a[i] < a[j]:
        		b[i][0] +=1


b[i][0]=b[i][0]%mod		
b[i][1]=b[i][1]%mod	
ans = 0
sigmakp = ((k * (k+1)% mod ) // 2) % mod
sigmakp = int(sigmakp)
sigmakn = ((k * (k-1)% mod) // 2) % mod
sigmakn = int(sigmakn)
for i in range(n):
    mae = int(sigmakn * b[i][0]) % mod
    ushiro = int(sigmakp * b[i][1]) % mod
    ans = int((mae + ushiro) + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
 
mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j  in range(i,n):
        if a[i] > a[j]:
                b[i][1] += 1
        elif a[i] < a[j]:
        		b[i][0] +=1


b[i][0]=b[i][0]%mod		
b[i][1]=b[i][1]%mod	
ans = 0
sigmakp = ((k * (k+1)% mod ) // 2) % mod
sigmakn = ((k * (k-1)% mod) // 2) % mod
for i in range(n):
    mae = int(sigmakn * b[i][0]) % mod
    ushiro = int(sigmakp * b[i][1]) % mod
    ans = int((mae + ushiro) + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
 
mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j  in range(i,n):
        if a[i] > a[j]:
                b[i][1] += 1
        elif a[i] < a[j]:
        		b[i][0] +=1


b[i][0]=b[i][0]%mod		
b[i][1]=b[i][1]%mod	
ans = 0
sigmakp = ((k * (k+1)% mod ) / 2) % mod
sigmakn = ((k * (k-1)% mod) / 2) % mod
for i in range(n):
    mae = int(sigmakn * b[i][0]) % mod
    ushiro = int(sigmakp * b[i][1]) % mod
    ans = int((mae + ushiro) + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
 
mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j  in range(i,n):
        if a[i] > a[j]:
                b[i][1] += 1
        elif a[i] < a[j]:
        		b[i][0] +=1
ans = 0
sigmakp = ((k * (k+1)% mod ) / 2) % mod
sigmakn = ((k * (k-1)% mod) / 2) % mod
for i in range(n):
    mae = int(sigmakn * b[i][0]) % mod
    ushiro = int(sigmakp * b[i][1]) % mod
    ans = int((mae + ushiro) + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
 
mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j  in range(i,n):
        if a[i] > a[j]:
            if i < j:
                b[i][1] += 1
        elif a[i] < a[j]:
        		b[i][0] +=1
ans = 0
sigmakp = int((k * (k+1)% mod ) / 2) % mod
sigmakn = int((k * (k-1)% mod) / 2) % mod
for i in range(n):
    mae = (sigmakn * b[i][0]) % mod
    ushiro = (sigmakp * b[i][1]) % mod
    ans = ((mae + ushiro) + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
 
mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            elif i<j:
                b[i][1] += 1
ans = 0
sigmakp = int((k * (k+1)% mod ) / 2) % mod
sigmakn = int((k * (k-1)% mod) / 2) % mod
for i in range(n):
    mae = (sigmakn * b[i][0]) % mod
    ushiro = (sigmakp * b[i][1]) % mod
    ans = ((mae + ushiro) + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
k = k % mod
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            elif i < j:
                b[i][1] += 1
    b[i][0] = b[i][0] % mod
    b[i][1] = b[i][1] % mod
ans = 0
# kまでの和　後ろの数用
sigmakp = ((k * (k+1)) / 2) % mod
sigmakp = int(sigmakp)
# k-1までの和　前の数用
sigmakn = ((k * (k-1)) / 2) % mod
sigmakn = int(sigmakn)

for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
 
mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            elif i<j:
                b[i][1] += 1
ans = 0
sigmakp = int((k * (k+1)) / 2) % mod
sigmakn = int((k * (k-1)) / 2) % mod
for i in range(n):
    mae = (sigmakn * b[i][0]) % mod
    ushiro = (sigmakp * b[i][1]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
k = k % mod
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            elif i < j:
                b[i][1] += 1
    b[i][0] = b[i][0] % mod
    b[i][1] = b[i][1] % mod
ans = 0
# kまでの和　後ろの数用
sigmakp = (((k * (k+1)) % mod) / 2) % mod
sigmakp = int(sigmakp)
# k-1までの和　前の数用
sigmakn = (((k * (k-1)) % mod) / 2) % mod
sigmakn = int(sigmakn)

for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
k = k % mod
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            else:
                b[i][1] += 1
    b[i][0] = b[i][0] % mod
    b[i][1] = b[i][1] % mod
ans = 0
# kまでの和　後ろの数用
sigmakp = (((k * (k+1)) % mod) / 2) % mod
sigmakp = int(sigmakp)
# k-1までの和　前の数用
sigmakn = (((k * (k-1)) % mod) / 2) % mod
sigmakn = int(sigmakn)

for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
 
mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            else:
                b[i][1] += 1
ans = 0
sigmakp = int(((k * (k+1)) % mod) / 2) % mod
sigmakn = int(((k * (k-1)) % mod) / 2) % mod
for i in range(n):
    mae = (sigmakn * b[i][0]) % mod
    ushiro = (sigmakp * b[i][1]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
nk=list(map(int,input().split()))
A=list(map(int,input().split()))
tentou=[]*(nk[0]-1)
for i in range(nk[0]-1):
    tentou.append([])
    for j in range(i+1,nk[0]):
        if A[i]>A[j]:
            tentou[-1].append(2)
        elif A[i]==A[j]:
            tentou[-1].append(1)
        else:
            tentou[-1].append(0)
ans=0
div=10**9+7
for i in range(nk[0]-1):
    if tentou[0][i]==2:
        ans+=1
ans=ans*int(((nk[1]*(nk[1]+1))%div)//2)
for i in range(1,nk[0]):
    back,forward=0,0
    for j in range(i):
        if tentou[j][i-j-1]==0:
            back+=1
    for j in range(nk[0]-1-i):
        if tentou[i][j]==2:
            forward+=1
    ans+=back*int(((nk[1]*(nk[1]-1))%div)//2)+forward*int(((nk[1]*(nk[1]+1))%div)//2)
ans=ans%div
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
 
mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            else:
                b[i][1] += 1
ans = 0
sigmakp = int(((k * (k+1)) % mod) / 2) % mod
sigmakn = int(((k * (k-1)) % mod) / 2) % mod
for i in range(n):
    mae = (sigmakn * b[i][1]) % mod
    ushiro = (sigmakp * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
k = k % mod
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            else:
                b[i][1] += 1
    b[i][0] = b[i][0] % mod
    b[i][1] = b[i][1] % mod
ans = 0
sigmakp = int(((k * (k+1)) % mod) / 2) % mod
sigmakn = int(((k * (k-1)) % mod) / 2) % mod
for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
nk=list(map(int,input().split()))
A=list(map(int,input().split()))
tentou=[]*(nk[0]-1)
for i in range(nk[0]-1):
    tentou.append([])
    for j in range(i+1,nk[0]):
        if A[i]>A[j]:
            tentou[-1].append(2)
        elif A[i]==A[j]:
            tentou[-1].append(1)
        else:
            tentou[-1].append(0)
ans=0
div=10**9+7
for i in range(nk[0]-1):
    if tentou[0][i]==2:
        ans+=1
ans=ans*int(((nk[1]*(nk[1]+1))%div)/2)
for i in range(1,nk[0]):
    back,forward=0,0
    for j in range(i):
        if tentou[j][i-j-1]==0:
            back+=1
    for j in range(nk[0]-1-i):
        if tentou[i][j]==2:
            forward+=1
    ans+=back*int(((nk[1]*(nk[1]-1))%div)/2)+forward*int(((nk[1]*(nk[1]+1))%div)/2)
ans=ans%div
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
k = k % mod
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            else:
                b[i][1] += 1
ans = 0
sigmakp = int(((k * (k+1)) % mod) / 2) % mod
sigmakn = int(((k * (k-1)) % mod) / 2) % mod
for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            else:
                b[i][1] += 1
ans = 0
sigmakp = int(((k * (k+1)) % mod) / 2) % mod
sigmakn = int(((k * (k-1)) % mod) / 2) % mod
for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

flip_N = 0
flip_global = 0

mod = 1000000007

for i in range(N):
    for j in range(N):
        if (i == j):
            continue
        if (A[i] > A[j]):
            flip_global += 1

            if (i < j):
                flip_N += 1

comb = int(K * (K-1) / 2) % mod

print(int((flip_N * K + flip_global * comb) % mod))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            else:
                b[i][1] += 1
ans = 0
sigmakp = int(((k * (k+1)) % mod) / 2) % mod
sigmakn = int(((k * (k-1)) % mod) / 2) % mod
for i in range(n):
    ans = (((sigmakp * b[i][1]) % mod) + ((sigmakn * b[i][0]) % mod) + ans) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            else:
                b[i][1] += 1
ans = 0
sigmakp = int(((k*(k+1))%mod)/2)%mod
sigmakn = int(((k*(k-1))%mod)/2)%mod
for i in range(n):
    ans = ((sigmakp * b[i][1] % mod) + (sigmakn * b[i][0] % mod) + ans) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            else:
                b[i][1] += 1
ans = 0
sigmakp = int(k*(k+1)/2) % mod
sigmakn = int(k*(k-1)/2) % mod
for i in range(n):
    ans = ((sigmakp * b[i][1] % mod) + (sigmakn * b[i][0] % mod) + ans) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            else:
                b[i][1] += 1
ans = 0
sigmakp = int(k*(k+1)/2)
sigmakn = int(k*(k-1)/2)
for i in range(n):
    ans = ((sigmakp * b[i][1] % mod) + (sigmakn * b[i][0] % mod) + ans) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
s=list(map(int,input().split()))
t=list(map(int,input().split()))
if s[0]==1:
  print(0)
else:
  x=0
  y=0
  z=0
  x=s[1]%1000000007
  y=(s[1]+1)%1000000007
  z=((x*y)/2)%1000000007
  p=0
  q=0
  r=0
  p=(s[1]-1)%1000000007
  q=s[1]%1000000007
  r=((p*q)/2)%1000000007
  b=0
  for i in range(s[0]):
    a=0
    for j in range(s[0]):
      if t[i]>t[j]:
        a=a+1
    b=b+a*r
    b=b%1000000007
  b=b%1000000007
  c=0
  for v in range(s[0]-1):
    a=0
    for w in range(v+1,s[0]):
      if t[v]>t[w]:
        a=a+1
    b=b+a*s[1]
    b=b%1000000007
  b=b%1000000007
  print(int(b))

Submission status: Wrong Answer

Solution code:
N, K =map(int, input().split())

A = list(map(int, input().split()))

mod=10**9 +7
count=0
for i in range(N):
  for j in range(i+1, N):
    if A[i]>A[j]:
      count+=K
  for k in range(N):
    if A[i]>A[k]:
      count+=(K-1)*K/2 % mod
  

print(int(count%mod))

Submission status: Wrong Answer

Solution code:
s=list(map(int,input().split()))
t=list(map(int,input().split()))
x=0
y=0
z=0
x=s[1]%1000000007
y=(s[1]+1)%1000000007
z=((x*y)/2)%1000000007
p=0
q=0
r=0
p=(s[1]-1)%1000000007
q=s[1]%1000000007
r=((p*q)/2)%1000000007
b=0
for i in range(s[0]):
  a=0
  for j in range(s[0]):
    if t[i]>t[j]:
      a=a+1
  b=b+a*r
  b=b%1000000007
b=b%1000000007
c=0
for v in range(s[0]-1):
  a=0
  for w in range(v+1,s[0]):
    if t[v]>t[w]:
      a=a+1
  b=b+a*s[1]
  b=b%1000000007
b=b%1000000007
print(int(b))

Submission status: Wrong Answer

Solution code:
s=list(map(int,input().split()))
t=list(map(int,input().split()))
x=0
y=0
z=0
x=s[1]%1000000007
y=(s[1]+1)%1000000007
z=((x*y)/2)%1000000007
p=0
q=0
r=0
p=(s[1]-1)%1000000007
q=s[1]%1000000007
r=((p*q)/2)%1000000007
b=0
for i in range(s[0]):
  a=0
  for j in range(s[0]):
    if t[i]>t[j]:
      a=a+1
  b=b+a*r
  b=b%1000000007
b=b%1000000007
c=0
for v in range(s[0]-1):
  a=0
  for w in range(v+1,s[0]):
    if t[v]>t[w]:
      a=a+1
  b=b+a*s[1]
  b=b%1000000007
b=b%1000000007
print(b)

Submission status: Wrong Answer

Solution code:
N, K =map(int, input().split())

A = list(map(int, input().split()))

mod=10**9 +7
count=0
for i in range(N-1):
  for j in range(i+1, N):
    if A[i]>A[j]:
      count+=K
  for k in range(N):
    if A[i]>A[k]:
      count+=(K-1)*K/2 % mod
  

print(int(count%mod))

Submission status: Wrong Answer

Solution code:
N, K =map(int, input().split())

A = list(map(int, input().split()))

mod=10**9 +7
count=0
for i in range(N-1):
  for j in range(i+1, N):
    if A[i]>A[j]:
      count+=K%mod
  for k in range(N):
    if A[i]>A[k]:
      count+=(K-1)*K/2 % mod
  

print(int(count%mod))

Submission status: Wrong Answer

Solution code:
mod=1000000000+7
N,K= (int(i) for i in input().split()) 
A = [int(i) for i in input().split()] 
B=[]
C=[0]*N
D=[0]*N
ans=0
for i in range(N):
    B.append(A[i])
for i in range(N):
    B.append(A[i])
    
for i in range(N):
    for j in range(i+1,i+N):
        if B[i]>B[j]:
            C[i]+=1
for i in range(N-1):
    for j in range(i+1,N):
        if A[i]>A[j]:
            D[i]+=1
print(C)
print(D)
for i in range(N):
    print(int((C[i]*(K-1)+2*D[i])*K//2) )
    ans+=int((C[i]*(K-1)+2*D[i])*K//2)
print(ans%mod)

Submission status: Wrong Answer

Solution code:
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
numc = 0
numf = 0

for i in range(0, N):
    for j in range(0,i):
        if A[j] > A[i]:
            numc += 1
        if A[i] > A[j]:
            numf += 1
numbers = numc*K+ numf*K*(K-1)/2
 
ans = int(numbers % (10**9 + 7))
print(ans)

Submission status: Wrong Answer

Solution code:
line_1=input().split()
number_line=input().split()

number_line1=list(map(int,number_line))
number_line2=[]
for i in range(int(line_1[1])):
	number_line2+=number_line1
#print(number_line2)
a=0
b=0
ans=0

for i in range(len(number_line2)):
	a=number_line2[i-1] #Bi
	for j in range(len(number_line2)):
		if i+j<=len(number_line2):
			b=number_line2[j+i-1]#Bj
			if a>b:
				ans+=1
print(ans%(10**9+7))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
li = list(map(int,input().split()))
mod = 10**9 +7
 
ans_1 = 0
ans_2 = 0
for i in range(n):
  for j in range(i+1,n):
    if li[i] > li[j]:
      ans_1+= 1
for i in range(n):
  for j in range(n):
    if li[i] > li[j]:
      ans_2 += 1
ans = k*ans_1%mod + (k*(k-1)/2)%mod*ans_2%mod
print(int(ans%mod))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
li = list(map(int,input().split()))
mod = 10**9 +7
 
ans_1 = 0
ans_2 = 0
for i in range(n):
  for j in range(i+1,n):
    if li[i] > li[j]:
      ans_1+= 1
for i in range(n):
  for j in range(n):
    if li[i] > li[j]:
      ans_2 += 1
ans = k*ans_1%mod + k%mod*(k-1)%mod//2*ans_2%mod
print(int(ans%mod))

Submission status: Wrong Answer

Solution code:
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
numc = 0
numf = 0

for i in range(0, N):
    for j in range(0,i):
        if A[j] > A[i]:
            numc += 1
        if A[i] > A[j]:
            numf += 1
numbers = numc*K*(K+1)+ numf*K*(K-1)
 
ans = int(numbers % (10**9 + 7) / 2)
print(ans)

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
mod=10**9+7
b=0
f=0
for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            #print(i,",",j)
            f+=1
           
            
for i in range(N-1,-1,-1):
    for j in range(i-1,-1,-1):
        if A[i]>A[j]:
            b+=1

ans=f*((K+1)*K/2)+b*((K-1)*K/2)
ans%=mod
print(int(ans))

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
mod=10**9+7
b=0
f=0
for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            #print(i,",",j)
            f+=1
           
            
for i in range(N-1,-1,-1):
    for j in range(i-1,-1,-1):
        if A[i]>A[j]:
            b+=1

ans=f*((K+1)*K/2)%mod+b*((K-1)*K/2)%mod
ans%=mod
print(int(ans))

Submission status: Wrong Answer

Solution code:
N, K =map(int, input().split())

A = list(map(int, input().split()))


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

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

Submission status: Wrong Answer

Solution code:
n, k = input().split()
l = list(map(int,input().split()))
n = int(n)
k = int(k)

rn_0 , rn_2 = 0, 0

for i in range(n-1):
  for j in range(i+1, n):
    if l[i] > l[j]:
      rn_0 += 1

for i in range(n):
  for j in range(0, i):
    if l[i] > l[j]:
      rn_2 += 1

rn = rn_0 * k*(k+1)/2 + rn_2 * k*(k-1)/2
print(int(rn%(10**9+7)))

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
mod=10**9+7
b=0
f=0
for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            #print(i,",",j)
            f+=1
           
            
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        if A[i]>A[j]:
            b+=1

ans=f*K
tmp=((K-1)*K)
ans+=((b*tmp)/2)
#ans = K * f + (b * K * (K - 1)) // 2
ans%=mod

print(int(ans))

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
mod=10**9+7
b=0
f=0
for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            #print(i,",",j)
            f+=1
           
            
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        if A[i]>A[j]:
            b+=1

ans=f*K
tmp=((K-1)*K)
ans+=((b*tmp)/2)
#ans = K * f + (b * K * (K - 1)) // 2
ans%=mod

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
mod=10**9+7
b=0
f=0
for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            #print(i,",",j)
            f+=1
           
            
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        if A[i]>A[j]:
            b+=1

ans=f*K
tmp=((K-1)*K)%mod
ans+=((b*tmp)//2)%mod
ans%=mod

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
mod=10**9+7
b=0
f=0
for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            #print(i,",",j)
            f+=1
           
            
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        if A[i]>A[j]:
            b+=1

ans=f*K
tmp=((K-1)*K)%mod
b/=2
ans+=(b*tmp)%mod
ans%=mod

print(int(ans))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/jsc2019-qual/tasks/jsc2019_qual_b
# B - Kleene Inversion

import math

n, k = list(map(int, input().split()))
a_list = list(map(int, input().split()))

w = (10 ** 9) + 7
unit_c = 0

# 1個の中だと
for i, a in enumerate(a_list[:-1]):
    unit_c += len([x for x in a_list[i:] if x < a])

appendix = 0
# print(a_list[-1], a_list[0])
if len(a_list) > 1:
    for a in a_list:
        # 自分より小さいやつの数
        appendix += len([x for x in a_list if x < a])

# 2回以上繰り返す場合
# print('unit_c: {}'.format(unit_c))
# print('appendix: {}'.format(appendix))

# total_tento_1 = unit_c * (k-1)
if k-1 == 1:
    work = 1
elif (k-1) % 2 == 0:
    work = (1 + (k-1)) * ((k-1) / 2)
else:
    mid_index = math.floor((k-1) / 2) + 1
    work = (1 + (k-1)) * math.floor((k-1) / 2)
    work += mid_index

t_1 = ((unit_c % w) * (k % w)) % w
t_21 = appendix % w
t_22 = work % w
t_2 = (t_21 * t_22) % w
ans = int((t_1 + t_2) % w)

# ans = ((unit_c * k) + (appendix * work)) % w
# total_amari = int(total_tento % w)
print(ans)