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:
import sys

input = sys.stdin.readline


def main():
    N, K = [int(i) for i in input().split()]
    a_list = [int(i) for i in input().split()]
    cnt = 0
    cnt = sum([a_list[i] > a_list[j] for i in range(N) for j in range(i, N)])
    second_cnt = sum([a_list[i] > a_list[j] for i in range(N) for j in range(i)])
    if K > 1:
        second_cnt *= (K * (K - 1)) / 2
    cnt = cnt * ((K * (K + 1)) / 2)
    # 2個まで見た方がいい？
    print((cnt + second_cnt) % (10 ** 9 + 7))
    # 185297239
    # 185297196.0
    # 43


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n, k = map(int, input().split())
a = list(map(int, input().split()))
num = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            num[i][1] += 1
        if (i < j) and (a[i] > a[j]):
            num[i][0] += 1
num_np = np.array(num)
if k % 2 == 0:
    ks = ((k / 2) % (10*9 + 7))
else:
    ks = k * (((k - 1) / 2) % (10*9 + 7))
sum_left = sum(num_np[:,0])
sum_right = sum(num_np[:,1])
output = (sum_left * k) % (10*9 + 7) + (sum_right * int(ks)) % (10*9 + 7)
print(output % (10*9 + 7))

Submission status: Wrong Answer

Solution code:
tempa=input().split()

n=int(tempa[0])
k=int(tempa[1])

ml=input().split()
a=[]
for i in range(n):
    kq=int(ml[i])
    a.append(kq)

mod=(10**9) +7

count=[]
temp=[]
for i in range(n):
    c=0
    t=0
    for l in range(i):
        if a[i]>a[l]:
            t=t+1
    for j in range(n-i):
        if a[i] > a[i+j]:
            c=c+1
    count.append(c*k*(k+1)*0.5)
    temp.append(t*k*(k-1)*0.5)

ans=sum(count)+sum(temp)
print(int(ans) % mod)

Submission status: Wrong Answer

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

def cal(A, N):
    cnt1 = 0
    cnt2 = 0
    for i in range(N):
        for j in range(i+1,N):
            if A[N-1-j] > A[N-1-i]:
                cnt1 += 1
    for i in range(N):
        for j in range(N):
            if A[N-1-i] < A[j]:
                cnt2 += 1
    
    return int(cnt1), int(cnt2)
    
    
x, y = cal(A,N)
R = int(1*10**9 +7)
tmp = int(K*(K-1)/2)
ans =  tmp*y + x*K
print(int(ans%R))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))


w = 10**9+7

As = sorted(A, reverse=True)
B = np.array(A)
C = np.argsort(B)[::-1]
for i in range(N-1):
    if As[i] == As[i+1]:
        for j in range(N):
            if C[j] > i:
                C[j] -= 1
        
        

cnt = 0

if  len(A) > 1:
    for i in range(N):
        rank = C[i]
        cnta = 0
        for j in range(i+1, N):
            if A[i] > A[j]:
                cnta += 1
        cnt += cnta*K
        for p in range(0, K):
            cnt += (N-1-rank)*p
    print(cnt%w)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, k = map(int, input().split())
a = list(map(int, input().split()))
num = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            num[i][1] += 1
        if (i < j) and (a[i] > a[j]):
            num[i][0] += 1
num_np = np.array(num)
if k % 2 == 0:
    ks = ((k / 2) % (10*9 + 7))
ks = k * (k - 1) / 2 % (10*9 + 7)
sum_left = sum(num_np[:,0])
sum_right = sum(num_np[:,1])
output = (sum_left * k) % (10*9 + 7) + (sum_right * int(ks)) % (10*9 + 7)
print(output % (10*9 + 7))

Submission status: Wrong Answer

Solution code:
N,K =map(int,input().split())
a = list(map(int,input().split()))
# print(a*K)
count = 0
dis = 0
for i in a:
    for k in a:
        if k < i:
            count +=1
        count %= (10 ** 9 + 7)
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1
        dis %= (10**9+7)
a = dis * K % (10**9+7)
b = count*K% (10**9+7)*(K-1)% (10**9+7)//2
ans = (a+b)% (10**9+7)
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
def count_inversion(sequence):
    count = 0
    for i in range(1,len(sequence),1):
        for j in range(i,len(sequence),1):
            if sequence[i-1] > sequence[j]:
                count += 1
    return count
def cnt_bigger_elem(sequence):
    cnt = 0
    for i in range(N):
        for elem in sequence:
            if sequence[i] < elem:
                cnt += 1
    return cnt

def cnt_smaller_elem(sequence):
    cnt = 0
    for i in range(N):
        for elem in sequence:
            if sequence[i] > elem:
                cnt += 1
    return cnt


#A = [1,2,3,5,4]

#print(cnt_bigger_elem(A))
#print(count_inversion(A))
BIG_NUM = 10**9+7
#ans0 = int((count_inversion(A) * K)%BIG_NUM + (K*(K-1)*cnt_bigger_elem(A)/2)%BIG_NUM)
#ans1 = int((count_inversion(A) * K)%BIG_NUM + ((K*(K-1)%(BIG_NUM))*cnt_bigger_elem(A))%BIG_NUM)
ans2 = int(((((count_inversion(A)%BIG_NUM) * (K%BIG_NUM))%BIG_NUM) + (((((K%BIG_NUM)*((K-1)%BIG_NUM))/2)%BIG_NUM)*(cnt_bigger_elem(A)%BIG_NUM))))%BIG_NUM
#ans3= int(K*((K-1)*cnt_bigger_elem(A)/2)+count_inversion(A))%BIG_NUM
#ans2 = int((((count_inversion(A) * K)%BIG_NUM) + (((((K%BIG_NUM)*((K-1)%BIG_NUM))/2)%BIG_NUM)*(cnt_bigger_elem(A)%BIG_NUM))))%BIG_NUM
#print(ans2)## 惜しい
#ans = int(((count_inversion(A)*K)%BIG_NUM + (((((K*(K-1))%BIG_NUM)*(0.5))%BIG_NUM)*(cnt_bigger_elem(A)%BIG_NUM)%BIG_NUM)%BIG_NUM))
print(ans2)
#print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
A = list(map(int,input().split()))
a = len(A)
MOD = 10**9+7
mae_cnt = 0
ato_cnt = 0
ans = 0

def seki(num):
  return int(num*(num+1)/2)

for i in range(a):
  ans += (mae_cnt*seki(k)) 
  ans += (ato_cnt*seki(k-1))
  mae_cnt = 0
  ato_cnt = 0
  for j in range(i+1,a):
    if A[i] > A[j]:
      mae_cnt += 1

  for x in range(i):
    if A[i] > A[x]:
      ato_cnt += 1
      
ans += (mae_cnt*seki(k)) 
ans += (ato_cnt*seki(k-1)) 

print(ans%MOD)

Submission status: Wrong Answer

Solution code:
def npr(n,r,ans=[]):
    if len(ans)==r:
        return ans
    for i in n:
        ans.append(i)
        n1=n[:]
        n1.pop(i)

N,K=map(int,input().split(" "))
A=list(map(int,input().split(" ")))
#N=3
#K=3
#A=[1,3,2]
A1=[set() for _ in range(N)]
cnt=0
cnt1=0
for n1 in range(N):
    for n2 in range(N):
        if n1!=n2 and A[n1]>A[n2]:
            cnt+=1
        if n1<n2 and A[n1]>A[n2]:
            cnt1+=1

#ten=int(cnt1+cnt*(K**2-K)/2+cnt1*(K-1))
k2=(K**2)%(10**9+7)
ten1=int((k2*cnt)%(10**9+7))
ten2=int((K*cnt)%(10**9+7))
ten3=int((cnt1*K)%(10**9+7))
if ten1-ten2<0:
    ten=(((ten1-ten2)+10**9+7)/2)%(10**9+7)
else:
    ten=((ten1-ten2)/2)%(10**9+7)
ten=ten+ten3
print(int(ten%(10**9+7)))

Submission status: Wrong Answer

Solution code:
M = 10**9+7
import sys
input = sys.stdin.readline
def main():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    A_ = sorted(A, reverse = True)
    ans = 0
    ans_ = 0
    for i in range(0,N-1):
        for j in range(i+1,N):
            if A[i] > A[j]:
                ans += 1
            if A_[i] > A_[j]:
                ans_ += 1

    print(int((((K*(K-1)/2)%M)*ans_+ans*K)%M))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
A = list(map(int,input().split()))
a = len(A)
MOD = 10**9+7
mae_cnt = 0
ato_cnt = 0
ans = 0

def seki(num):
  return int(num*(num+1)/2)

for i in range(a):
  ans += (mae_cnt*seki(k)) % MOD
  ans += (ato_cnt*seki(k-1)) % MOD
  mae_cnt = 0
  ato_cnt = 0
  for j in range(i+1,a):
    if A[i] > A[j]:
      mae_cnt += 1

  for x in range(i):
    if A[i] > A[x]:
      ato_cnt += 1
      
ans += (mae_cnt*seki(k)) % MOD
ans += (ato_cnt*seki(k-1)) % MOD   

print(ans%MOD)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
def count_inversion(sequence):
    count = 0
    for i in range(1,len(sequence),1):
        for j in range(i,len(sequence),1):
            if sequence[i-1] > sequence[j]:
                count += 1
    return count
def cnt_bigger_elem(sequence):
    cnt = 0
    for i in range(N):
        for elem in sequence:
            if sequence[i] < elem:
                cnt += 1
    return cnt

def cnt_smaller_elem(sequence):
    cnt = 0
    for i in range(N):
        for elem in sequence:
            if sequence[i] > elem:
                cnt += 1
    return cnt


#A = [1,2,3,5,4]

#print(cnt_bigger_elem(A))
#print(count_inversion(A))
BIG_NUM = 10**9+7
#ans0 = int((count_inversion(A) * K)%BIG_NUM + (K*(K-1)*cnt_bigger_elem(A)/2)%BIG_NUM)
#ans1 = int((count_inversion(A) * K)%BIG_NUM + ((K*(K-1)%(BIG_NUM))*cnt_bigger_elem(A))%BIG_NUM)
ans2 = int(((((count_inversion(A)%BIG_NUM) * (K%BIG_NUM))%BIG_NUM) + (((((K%BIG_NUM)*((K-1)%BIG_NUM))/2)%BIG_NUM)*(cnt_smaller_elem(A)%BIG_NUM))))%BIG_NUM
#ans3= int(K*((K-1)*cnt_bigger_elem(A)/2)+count_inversion(A))%BIG_NUM
#ans2 = int((((count_inversion(A) * K)%BIG_NUM) + (((((K%BIG_NUM)*((K-1)%BIG_NUM))/2)%BIG_NUM)*(cnt_bigger_elem(A)%BIG_NUM))))%BIG_NUM
#print(ans2)## 惜しい
#ans = int(((count_inversion(A)*K)%BIG_NUM + (((((K*(K-1))%BIG_NUM)*(0.5))%BIG_NUM)*(cnt_bigger_elem(A)%BIG_NUM)%BIG_NUM)%BIG_NUM))
print(ans2)
#print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
h=0 #hidariyoridekai
m=0 #migiyoridekai
for i in range(n):
    for j in range(n):
        if (a[i]>a[j]) and (i>j):
            h += 1
        elif (a[i]>a[j]) and (i<j):
            m += 1
MOD = 10**9+7

ans=( ((((k+1)*k)%MOD)*m/2)%MOD + ((((k-1)*k)%MOD)*h/2)%MOD ) %MOD
print(int(ans))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split(" "))
A=list(map(int,input().split(" ")))
#N=3
#K=3
#A=[1,3,2]
A1=[set() for _ in range(N)]
cnt=0
cnt1=0
for n1 in range(N):
    for n2 in range(N):
        if n1!=n2 and A[n1]>A[n2]:
            cnt+=1
        if n1<n2 and A[n1]>A[n2]:
            cnt1+=1

#ten=int(cnt1+cnt*(K**2-K)/2+cnt1*(K-1))
k2=(K**2)%(10**9+7)
ten1=int((k2*cnt)%(10**9+7))
ten2=int((K*cnt)%(10**9+7))
ten3=int((cnt1*K)%(10**9+7))
if ten1-ten2<0:
    ten=(((ten1-ten2)+10**9+7)/2)%(10**9+7)
else:
    ten=((ten1-ten2))/2%(10**9+7)
ten=ten+ten3
print(int(ten%(10**9+7)))

Submission status: Wrong Answer

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


li = []

for i in range(n):
    count=0
    for j in range(n):
        if List[i]>List[j]:
            count += 1
    li.append(count)
print(str(sum(li))+"li")


count2=0

for i in range(1,n):
    for j in range(i+1,n+1):
        #print(i,j)
        if int(List[i-1]) > int(List[j-1]):
            count2 += 1
    #print(str(count2)+"count2")


for m in range(k,0,-1):
    counted=count2+count2*(m-1)




ans = counted % 1000000007
print(ans)

Submission status: Wrong Answer

Solution code:
#######################################
prime = 10**9+7

def sowa(num):
  return int((1+num)*num/2)
#######################################
n,k = map(int, input().split())
a = list(map(int, input().split()))

tento1 = [sum([1 if a[i]>a[j] else 0 for j in range(i+1,n)]) for i in range(n-1)]
tento2 = [sum([1 if a[i]>a[j] else 0 for j in range(n)]) for i in range(n)]


ret = (sum(tento1) *k %prime) + (sum(tento2) *(sowa(k) %prime) %prime)
print(ret%prime)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]

mod = 10**9+7

g = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a[i] > a[j]:
            #print(i,j)
            g += 1

if k == 1:
    print(g)
    exit()
    
a2 = []

for i in range(2*n):
    a2.append(a[i%n])
    
f = 0

for i in range(n):
    for j in range(2*n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a2[i] > a2[j]:
            #print(i,j)
            f += 1

t = (f-g)%mod

#print(t)
#exit()
#print(int((k*g%mod + t*(0.5*((k-1)*k))%mod)%mod))
#print(int(( (k%mod*g%mod)%mod + (t*(0.5*((k-1)%mod*k%mod)) ) %mod)%mod))
#print(int((k*g%mod + t*(0.5*((k-1)%mod*k%mod))%mod)%mod))
ans1 = (k*g%mod)
ans2 = t*(0.5* (k-1)%mod * k%mod ) %mod
print( int( (ans1 + ans2)%mod ))
#print(int(((k*g) + (t*(0.5*((k-1)*k))))%mod))
exit()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
s = [sum([b > c for c in a]) for b in a]
l = [sum([l < a[i] for l in a[:i]]) for i in range(1, len(a))]
l.insert(0, 0)
r = [b - c for b, c in zip(s, l)]
a = sum(r) * (1+K)*K/2 + sum(l) * (K-1)*K/2
print(int(a%(1e9+7)))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
sum1 = 0
sum2 = 0
for i in range(n-1):
    for j in range(i+1, n):
        if a[i]>a[j]:
            sum1+=1
        elif a[i]<a[j]:
            sum2+=1
ans = sum1*k*k+(sum2-sum1)*k*(k-1)/2
print(ans%1e9+7)

Submission status: Wrong Answer

Solution code:
import copy

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
s = 0
n,r =ips()
a = iprow()
for i in a[:-1]:
    for k in a[1:]:
        if i>k:s+=1
adder = 0
rate = s
ans = 0
ans = (((1 + r) * r) // 2)*rate%rem
print(ans%rem)

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

m = l*2
for i in range(n*2):
  for j in range(0, i):
    if m[i] > m[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:
def main():
	N, K = [int(f) for f in input().split()]
	A = [int(f) for f in input().split()]

	c = 0
	for i, a in enumerate(A):
		#print(sum([f<a for f in A2[i+1:]]))
		c += sum([f<a for f in A[i+1:]])
	c2 = 0
	A2 = A+A
	for i, a in enumerate(A2):
		#print(sum([f<a for f in A2[i+1:]]))
		c2 += sum([f<a for f in A2[i+1:]])
	aa = c2 - c
	A3 = A+A+A
	c3 = 0
	for i, a in enumerate(A3):
		#print(sum([f<a for f in A2[i+1:]]))
		c3 += sum([f<a for f in A3[i+1:]])
	d = (c3 - c2) - (c2 - c)
	K -= 1

	#print(aa, d)
	
	counter = int((K * (2 * aa + (K-1) * d)) / 2)
	counter += c
	#print(counter)
	print(counter%(10**9+7))

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
b=a*3
c1 = 0
c2 = 0
c3 = 0

for i in range(n*3):
	for j in range(i,n*3,1):
		if b[i] > b[j]:
			c3+=1
			if i < n*2 and j < n*2:
				c2+=1
				if i < n and j < n:
					c1+=1

diff_c1 = c2-c1
diff_c2 = c3-c2
diff_c = diff_c2 - diff_c1

m = 10**9 + 7
all_s =( 0.5*((2*diff_c1%m+(k-2)*diff_c%m) * (k-1)%m))

if k == 1:
	print("%d" % int(c1%m))
elif k == 2:
	print("%d" % int(c2%m))
elif k == 3:
	print("%d" % int(c3%m))
else:
	print("%d" % ((c1+all_s)%m))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split(" "))
A=list(map(int,input().split(" ")))
#N=3
#K=3
#A=[1,3,2]
A1=[set() for _ in range(N)]
cnt=0
cnt1=0
for n1 in range(N):
    for n2 in range(N):
        if n1!=n2 and A[n1]>A[n2]:
            cnt+=1
        if n1<n2 and A[n1]>A[n2]:
            cnt1+=1

#ten=int(cnt1+cnt*(K**2-K)/2+cnt1*(K-1))
k2=(K**2)%(10**9+7)
ten1=int((k2*cnt)%(10**9+7))
ten2=int((K*cnt)%(10**9+7))
ten3=int((cnt1*K)%(10**9+7))
if ten1-ten2<0:
    ten=((ten1-ten2+10**9+7)/2)%(10**9+7)
else:
    ten=((ten1-ten2))/2%(10**9+7)
ten=ten+ten3
print(int(ten%(10**9+7)))

Submission status: Wrong Answer

Solution code:

def main():
	N, K = [int(f) for f in input().split()]
	A = [int(f) for f in input().split()]

	c = 0
	for i, a in enumerate(A):
		#print(sum([f<a for f in A2[i+1:]]))
		c += sum([f<a for f in A[i+1:]])
	c2 = 0
	A2 = A+A
	for i, a in enumerate(A2):
		#print(sum([f<a for f in A2[i+1:]]))
		c2 += sum([f<a for f in A2[i+1:]])
	aa = c2 - c
	A3 = A+A+A
	c3 = 0
	for i, a in enumerate(A3):
		#print(sum([f<a for f in A2[i+1:]]))
		c3 += sum([f<a for f in A3[i+1:]])
	d = (c3 - c2) - (c2 - c)
	K -= 1

	print(aa, d)
	
	counter = int((K * (2 * aa + (K-1) * d)) / 2)
	counter += c
	#print(counter)
	print(counter%(10**9+7))

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:

def main():
	N, K = [int(f) for f in input().split()]
	A = [int(f) for f in input().split()]

	c = 0
	for i, a in enumerate(A):
		#print(sum([f<a for f in A2[i+1:]]))
		c += sum([f<a for f in A[i+1:]])
	c2 = 0
	A2 = A+A
	for i, a in enumerate(A2):
		#print(sum([f<a for f in A2[i+1:]]))
		c2 += sum([f<a for f in A2[i+1:]])
	aa = c2 - c
	A3 = A+A+A
	c3 = 0
	for i, a in enumerate(A3):
		#print(sum([f<a for f in A2[i+1:]]))
		c3 += sum([f<a for f in A3[i+1:]])
	d = (c3 - c2) - (c2 - c)
	K -= 1

	print(aa, d)
	
	counter = int((K * (2 * aa + (K-1) * d)) / 2)
	counter += c
	print(counter)
	print(counter%(10**9+7))

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import *
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    m, d = LI()
    ans = 0
    for i in range(1, m + 1):
        for j in range(10, d + 1):
            if int(str(j)[0]) < 2 or int(str(j)[1]) < 2:
                continue
            if i == int(str(j)[0]) * int(str(j)[1]):
                ans += 1
    print(ans)
    return

#B
def B():
    n, l = LI()
    a = LI()
    d0 = defaultdict(int)
    d1 = defaultdict(int)
    for i in a:
        d0[i] += 1
    for i in range(n):
        b = 0
        for k in range(i+1, n):
            if a[i] > a[k]:
                b += 1
        d1[i] = b
    ans = 0
    d2 = list(d0.items())
    d2.sort()
    d3 = defaultdict(int)
    d = 0
    for key, value in d2:
        d3[key] = d
        d += value
    print(d3,d1)
    for i in range(n):
        ans += d3[a[i]] * l * (l-1) // 2 + d1[i] * l
        ans %= mod
    print(ans % mod)
    return

#C
def C():
    n = II()
    s = itertools.product([1, 0], repeat=2 * n)
    a = list(itertools.combinations(range(2*n), 2))
    d = defaultdict(int)
    def dfs(a):
        if len(a) == n:
            lis.append(a)
            return True
        for i in range(n):
            if d[i] == 0:
                d[i] = 1
                for k in range(n):
                    if d[k] == 0:
                        d[k] = 1
                        a.append((i, k))
                        dfs(a)
                        a.remove((i, k))
    lis = []
    dfs([])
    for si in s:
        for di in lis:
            b = list(si[::1])
            for x, y in di:
                for i in range(x, y + 1):
                    b[i] ^= 1
            if sum(b) < 1:
                print(si, di)
                break

    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split(" "))
A=list(map(int,input().split(" ")))
#N=3
#K=3
#A=[1,3,2]
A1=[set() for _ in range(N)]
cnt=0
cnt1=0
for n1 in range(N):
    for n2 in range(N):
        if n1!=n2 and A[n1]>A[n2]:
            cnt+=1
        if n1<n2 and A[n1]>A[n2]:
            cnt1+=1

#ten=int(cnt1+cnt*(K**2-K)/2+cnt1*(K-1))
k2=(K**2)%(10**9+7)
ten1=int((k2*cnt)%(10**9+7))
ten2=int((K*cnt)%(10**9+7))
ten3=int((cnt1*K)%(10**9+7))
if ten1-ten2<0:
    ten=((ten1-ten2+10**9+7)/2)%(10**9+7)
else:
    ten=((ten1-ten2))/2%(10**9+7)
ten=ten+ten3
print(ten%(10**9+7))

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def count_inversion(sequence):
    return sum(sum(m<n for m in sequence[i+1:]) for i,n in enumerate(sequence))

def count_ponpon(sequence):
    counter = 0
    split_count = 0
    splited = 0
    num = len(sequence)
    for i in sequence:
        split_count = sequence.count(i)
        counter += (num - split_count - splited)
        splited += 1
        
    logging.info(counter)
    return counter
        

def main():
    N, K = map(int, input().split())
    A_1 = list(map(int, input().split()))
    MODI = 10 ** 9 + 7
    logging.info("Hello!")

    A_counter = count_inversion(A_1)
    k_counter = int((K) * (K - 1) / 2)
    
    A_ = count_ponpon(A_1)
    
    print((A_counter * K + k_counter * A_) % MODI)
        
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
count_fall = 0
count_fall_a = 0
b=sorted(a,reverse=True)
for i in range(len(a)):
  for j in range(i + 1, len(a)):
    if b[i] > b[j]:
      count_fall += 1
    if a[i] > a[j]:
      count_fall_a += 1
SIGMA_sum = (k * (k+1)) // 2
print(((SIGMA_sum)*(count_fall))%(10**9+7))

Submission status: Wrong Answer

Solution code:
N,K = [int(i) for i in input().split()]
A_list = [int(i) for i in input().split()]

mod = 10**9+7


rightlist = [0 for i in A_list]
alllist = [0 for i in A_list]

for i in range(len(A_list)):
    ct1 = 0
    ct2 = 0
    a = A_list[i]
    right = A_list[i:]
    
    for j in right:
        #print(a,j)
        if a > j:
            ct1+=1
    
    for j in A_list:
        if a > j:
            ct2+=1
    rightlist[i] = ct1
    alllist[i] = ct2


R = int(sum(rightlist))
A  =int(sum(alllist))
K = int(K%mod)
R = int(R%mod)
A = int(A%mod)

ans = int(int(R*K)+A*int(K*(K-1)*2**-1))
print(ans%mod)

Submission status: Wrong Answer

Solution code:
x = list(map(int, input().split()))
N, K = x[0], x[1]
A = list(map(int, input().split()))
count_up = 0
count_down = 0
waru = 10**9+7

num_up = (1 + K) * K / 2

for i in range(N):
    for j in range(0, i):
        if A[i] > A[j]:
            count_down += 1
    for j in range(i+1,N):
        if A[i] > A[j]:
            count_up += 1

result = (num_up * count_up + num_up * (count_down - 1)) % waru

print(int(result))

Submission status: Wrong Answer

Solution code:
#coding: utf-8
n,k = map(int, input().split())
stra = list(map(int,input().split()))
strb = []
# for i in range(k):
# 	strb = strb + stra
ans = 0
sss = 0
# print(stra)
# print(strb)

for i in range(len(stra)-1):
	for j in range(i+1,len(stra)):
		if stra[i] > stra[j]:
			ans += 1
	print(ans)
print(ans)
# for p in range(k):
# 	sss += p+1
sss = k * (k+1) /2% (1000000000+7)
# print(sss)
print(round((ans * sss)))

Submission status: Wrong Answer

Solution code:
N,K=(int(x) for x in input().split())
C=list((int(x) for x in input().split()))
B=[0 for i in range(N*K)]
A=[]
for i in range(K):
  A+=C
sum00=0
sum0=0
for i in range(N*K):
  B[A[i]-1]+=1
  sum0+=i+1-sum(B[:i+1])
print(sum0)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
rcount=0
lcount=0
for i in range(n-1):
  for j in range(i+1,n):
    if a[i]>a[j]:
      rcount+=1

for i in range(n-1):
  for j in range(i+1,n):
    if a[i]<a[j]:
      lcount+=1

#print(count,countlast)
mod=10**9+7

print((k*(k+1)*rcount+k*(k-1)*lcount)/2%mod)

Submission status: Wrong Answer

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


def inversion(A):
    cnt = 0
    for i in range(len(A)):
        for j in range(len(A) - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                cnt += 1
    return cnt


unq = len(set(A))
inv_a = inversion(A)

tmp0 = inv_a * K
tmp1 = unq * (unq - 1) / 2 * K * (K - 1) / 2
tmp2 = tmp0 + tmp1
result = int(tmp2) % int(1e9 + 7)

print(result)

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
A2 = A * 2
a = [0]*2*N
for i in range(len(A2)):
    for j in A2[i+1:]:
        if A2[i] > j:
            a[i] += 1
if K >= 2:
    b1sum = 0
    b1 = a[0:N]
    b2 = a[N:]
    for i in range(N):
        b1sum += b1[i]-b2[i]

    print(int((K*(K-1)/2*b1sum+K*sum(b2))%(10**9+7)))
else:
    print(sum(a[N:]))

Submission status: Wrong Answer

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

MOD=10**9+7

arr=[0]*N
for i, ai in enumerate(A[:-1]):
    cnt=0
    for aj in A[i+1:]:
        if ai > aj:
            cnt+=1
    arr[i]=cnt
s=sum(arr)

arr.sort(reverse=True)
arr=[0]*N
for i, ai in enumerate(A[:-1]):
    cnt=0
    for aj in A[i+1:]:
        if ai > aj:
            cnt+=1
    arr[i]=cnt
s2=sum(arr)


v=(K+1)*K//2



print((s*K+v*s2)%MOD)

Submission status: Wrong Answer

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

single_counts = [0] * (n - 1)
all_counts = [0] * n
for i in range(n - 1):
  for j in range(i + 1, n):
    if As[i] > As[j]:
      single_counts[i] += 1
      all_counts[i] += 1
    elif As[i] < As[j]:
      all_counts[j] += 1
      
count = 0
count += int(((0.5 * (k ** 2 - k)) * sum(all_counts)) % (10 ** 9 + 7))
count += k * sum(single_counts)
print(int(count % (10 ** 9 + 7)))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]

mod = 10**9+7

g = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a[i] > a[j]:
            #print(i,j)
            g += 1

if k == 1:
    print(g)
    exit()
    
a2 = []

for i in range(2*n):
    a2.append(a[i%n])
    
f = 0

for i in range(n):
    for j in range(2*n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a2[i] > a2[j]:
            #print(i,j)
            f += 1

t = (f-g)%mod

#print(t)
#exit()
#print(int((k*g%mod + t*(0.5*((k-1)*k))%mod)%mod))
#print(int(( (k%mod*g%mod)%mod + (t*(0.5*((k-1)%mod*k%mod)) ) %mod)%mod))
ans1 = (k%mod*g%mod)
ans2 = t*(0.5* (k-1)%mod * k%mod ) 
print( int( (ans1 + ans2)%mod ))
#print(int(((k*g) + (t*(0.5*((k-1)*k))))%mod))
exit()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
from scipy.misc import comb
def main():
    input = sys.stdin.readline
    NK = list(map(int, input().split()))
    N = NK[0]
    K = NK[1]
    As = np.array(list(map(int, input().split())))
    ans = 0
    D = 1000000007
    """
    # 端の大きさ
    start = As[0]
    stop = As[-1]
    startstop = 0
    if start < stop:
        startstop += 1
    """
    inv_t = [0]+[1]
    for i in range(2,3):
      inv_t += [inv_t[D % i] * (D - int(D / i)) % D]
    # 内部での組み合わせ
    cnt_next = 0
    for i in range(N):
        cnt_next += np.count_nonzero(As[:-1-i] < As[-i-1])
        
    #print(cnt_next)
    cnt_naibu = (comb(cnt_next+1,2) % D).astype("int64")
    #print(cnt_naibu)
    cnt_naibu_ans = (cnt_naibu * K) % D
    # 外部でいくつ増えるか
    cnt_next_gaibu = 0
    for i in range(N):
        cnt_next_gaibu += np.count_nonzero(As<As[i])
    #print(cnt_next_gaibu)
    cnt_gaibu_ans = cnt_next_gaibu % D * (K%D * (K%D -1)) * inv_t[2] %D
    #print(cnt_gaibu_ans)
    ans = cnt_gaibu_ans % D + cnt_naibu_ans % D
    ans = ans % D
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
a0_list = []
d_list = []
s_list = []

#a0_list
for k in range(N):
    c = 0
    for i in range(k+1,N):
        if A[k]>A[i]:
            c += 1
    a0_list.append(c)

#d_list
for l in range(N):
    c = 0
    for m in A:
        if A[l]>m:
            c += 1
    d_list.append(c)

for n in range(N):
    end = a0_list[n] + (K-1)*d_list[n]
    s = ((a0_list[n] + end)*K)/2
    s_list.append(s)

S = sum(s_list)
p = (10**9) + 7
ans = S%p
print(int(ans))

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))

def count_inversion(sequence):
	count = 0
	for i in range(1,len(sequence),1):
		for j in range(i,len(sequence),1):
			if sequence[i-1] > sequence[j]:
				count += 1
	return count

a = (count_inversion(nums) % mod) * k
nums_s = sorted(nums)
b = count_inversion(nums_s + nums_s) % mod
c = ((k - 1) * k / 2) % mod
print(int((a + b * c) % mod))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
h=0 #hidariyoridekai
m=0 #migiyoridekai
for i in range(n):
    for j in range(n):
        if (a[i]>a[j]) and (i>j):
            h += 1
        elif (a[i]>a[j]) and (i<j):
            m += 1
MOD = 10**9+7

ans=(((((((k+1)*k)%MOD)*m)%MOD)/2)%MOD + ((((((k-1)*k)%MOD)*h)%MOD)/2)%MOD)%MOD
print(int(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i, j in enumerate(a, 0):
    for h in a[i:]:
        if j > h:
            count += 1

def result(n, count):
    return count + (count * n * (n-1)) / 2 + count * (n - 1)

if count == 0:
    print(0)
else:
    print(int(result(k, count) % (10**9 + 7)))

Submission status: Wrong Answer

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

tota = 0
totd = 0

for i in range(N): # iは0からN-1
    for j in range(i+1, N): # jはi+1からN-1
        if A[i] > A[j]:
            tota += 1
    for k in range(N): # kは0からN-1
        if A[i] > A[k]:
            totd += 1

print(int((((K%1000000007)/2)*(2*tota + ((K-1))*totd)%1000000007)%1000000007))