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:
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)
g = round(K*(K-1)/2)
a = dis * K % (10**9+7)
b = count*g%(10**9+7)
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()))

x = 0
for l in range(N - 1):
  for r in range(l + 1, N):
    if A[l] > A[r]:
      x += 1
# print(x)
      
AA = A + A
y = 0
for l in range(2 * N - 1):
  for r in range(l + 1, 2 * N):
    if AA[l] > AA[r]:
      y += 1
y -= 2 * x
# print(y)
  
# print(int((K * x + K * (K - 1) * y / 2) % (10 ** 9 + 7)))
# print(int((K * x  % (10 ** 9 + 7) + K * (K - 1) * y / 2  % (10 ** 9 + 7)) % (10 ** 9 + 7)))
kkmod = (K * (K - 1)) % (10 ** 9 + 7)
kkmod = (1 / 2 * kkmod * y) % (10 ** 9 + 7)
Kxmod = (K * x) % (10 ** 9 + 7)
ans = (Kxmod + kkmod) % (10 ** 9 + 7)
print(int(ans))

Submission status: Wrong Answer

Solution code:
mo=0
moz=0
mozk=0
zemmo=0
intl=[]
tentl=[]
b=[]
for x in input().split(" "):
    b.append(int(x))
a=[]
for x in input().split(" "):
    a.append(int(x))
i=0
while i<len(a)-1:
    j=i+1
    while j<len(a):
        if a[i]>a[j]:
            mo+=1
        j+=1
    i+=1
i=0
intl=[0]*2001
for x in a:
    intl[x]+=1
i=b[0]
for x in intl:
    i-=x
    tentl.append(i)
for x in tentl:
    moz+=x
moz-=tentl[0]
mozk=int(moz*(b[1]-1)/2)%(1000000000+7)
mozkk=int(mozk*b[1])%(1000000000+7)
print((mozkk+mo*b[1])%(1000000000+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:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 24 21:32:07 2019

@author: kato yugo
"""

n, k = map(int,input().split())
a_li = input().split()
mod = 10**9 +7

a = [0 for i in range(n+1)]

for i in range(n):
    a[i] = int(a_li[i])
a[n] = 10**10   
 
ans_memo = [0 for i in range(n)]   
for i in range(n):
    for j in range(i+1,n+1):
        if a[i]>a[j]:
            ans_memo[i] += 1

ans = 0

for i in range(n):
    q = ans_memo[i]
    ans += (q*k)%mod
    
a2 = a
a3 = sorted(a2,reverse=True)

qqq = 0
memo2 = 1
for i in range(1,n):
    if a3[i] > a3[i+1]:
        qqq += memo2*(n-i)
        memo2 = 1
    elif a3[i] == a3[i+1]:
        memo2 += 1
    
total = int(((k-1)*(k-2))/2)%mod
ans += qqq*total


print(ans%mod)

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

Submission status: Wrong Answer

Solution code:
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
Kmin = K % (10**9 + 7)
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*Kmin*(Kmin+1)+ numf*Kmin*(Kmin-1)
 
ans = int(numbers % (10**9 + 7) / 2)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
  print("0")
  exit()
ans_unit = 0
for i in range(n-1):
  for j in range(i+1, n):
    if a[i] > a[j]:
      ans_unit+=1
if k == 1:
  print(ans_unit)
  exit()
c = sum([a,a], [])
ans_inc =0
for i in range(0,n):
  for j in range(n, 2*n):
    if c[i] > c[j]:
      ans_inc+=1
ans = (k*ans_unit)%1000000007
tmp_ans = int(k*(k-1)/2)%1000000007
tmp_ans *=ans_inc
ans += tmp_ans
ans = ans%1000000007
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
kaisa = 0
ans_2 = 0
for i in range(1,len(A)):
    for j in range(0,i):
        if A[j]>A[i]:
            ans += 1
kaisa = ans
for i in range(math.ceil(math.sqrt(K))):
    ans_2 += kaisa
    kaisa += ans
ans_2 = ans_2*2-1
print((ans_2)%10000000007)

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*((diff_c1+(k-2)*diff_c+diff_c1)%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:
import numpy as np

MOD = 1e+9 + 7
N, K = map(int, input().split())
Alist = list(map(int, input().split()))

Alist_sorted = sorted(Alist)
tmp = 0
tmp2 = 0
for i in range(1, len(Alist)):
    if Alist_sorted[i] == Alist_sorted[i-1]:
        tmp2 += 1
    else:
        tmp2 = 0
    tmp += i - (tmp2)
ans = (tmp * ((K * (K-1) / 2) % MOD)) % MOD

Alist = Alist[::-1]
for i in range(1, len(Alist)):
    ans += ((np.sum(np.array(Alist[:i]) < Alist[i]) * K))
    ans = ans % MOD
ans = ans % MOD
print(int(ans))

Submission status: Wrong Answer

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

B = A * 2
base1 = 0
base2 = 0

for i in range(N):
    count1 = 0
    count2 = 0
    for j in range(i+1, i+1+N):
        if B[i] > B[j]:
            if j < N:
                count1 += 1
            else:
                count2 += 1
        
    base1 += count1
    base2 += count2

    count1 = 0
    count2 = 0
    
ans = int((1/2)*(base1*K*(K+1)+base2*(K-1)*K)) 

if K > 10000:
    ans += base1
    
divisor = 1000000007

print(ans % divisor)

Submission status: Wrong Answer

Solution code:
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:
    # print('even')
    work = (1 + (k-1)) * ((k-1) / 2)
else:
    # print('odd')
    mid_index = math.floor((k-1) / 2) + 1
    # print(mid_index)
    work = (1 + (k-1)) * math.floor((k-1) / 2)
    # print(work)
    work += mid_index
# print(work)
# work_2 = sum([x for x in range(1, k-1)])
# print(work, work_2)
# total_tento = unit_c + (unit_c + appendix) * work
t_1 = (unit_c * k) % w
t_21 = appendix % w
t_22 = work % w
t_2 = (t_21 * t_22) % w
total_amari = int((t_1 + t_2) % w)

# print('------')
# print(total_tento)
# total_amari = int(total_tento % w)
print(total_amari)

Submission status: Wrong Answer

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

b = a
ans = 0

for i in range(len(b)):
  for j in range(len(b[i:])):
    if b[i] > b[j]:
      ans += 1
  

mul = (n * n-1) / 2

ans = ans * k * mul

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

Submission status: Wrong Answer

Solution code:

N, K = map(int, input().split())
A = [int(v) for v in input().split()]

c0 = 0
for i in range(N - 1):
    if A[i] > A[i + 1]:
        c0 += 1

cc = (c0 + 1) * c0 / 2

r = (c0 * K) + ((K - 1) * K / 2) * cc
# r = cc
# for i in range(K):
#     r += c0 + (cc * i)
#     r %= MOD
MOD = int(10 ** 9) + 7
print(int(r) % MOD)

Submission status: Wrong Answer

Solution code:
n,k  = (int(i) for i in input().split())
a = [int(j) for j in input().split()]
b = a
#b = a * k
#print(b)
c = range(0,n)
resb = 0
ress = 0
for d in c:
 e = range(0,n)
 for f in e:
  #print(d,f)
  if b[d] > b[f]:
   #print(b[d],">",b[f])
   #print(d,f)
   resb = resb + 1
  if b[d] < b[f]:
    #print(b[d],"<",b[f])
    ress = ress + 1
#print(resb)
#print(ress)
ppp = resb * k + ress * (k-1)
#print(ppp)
print(ppp % 1000000007)

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


#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().strip().split())
list = list(map(int, input().strip().split()))
s = 0
t = 0
k = k


for i in range(n):
    for j in range(i, n):
        if list[i] > list[j]:
            s += 1
            
list.reverse()           
for i in range(n):
    for j in range(i, n):
        if list[i] > list[j]:
            t += 1            

            
a = (k**2+k)%1000000007          
a = int(a/2)
b = (k**2-k)%1000000007
b = int(b/2)

print(int((a*s+b*t)%1000000007))

Submission status: Wrong Answer

Solution code:
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
Mod = 1000000007




def main(): #startline-------------------------------------------
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    ans = 0
    for i in range(n):
        for j in range(n-1,i,-1):
            if a[j] < a[j-1]:
                a[j],a[j-1] = a[j-1],a[j]
                ans += 1
    u = Counter(a)
    ul = list(u.keys())
    ul.sort(reverse = True)
    p = len(set(a))   
    ans *= k
    temp = 0
    for i in range(p):
        temp += u[ul[i]]
        ans += (n-temp)*(k*(k-1)//2)
        ans %= Mod
    print(ans)

if __name__ == "__main__":
    main() #endline===============================================





def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n,k = map(int,stdin.readline().rstrip().split())
li = list(map(int,stdin.readline().rstrip().split()))
li_to = li*2
nai = 0
ato = 0
for i in range(len(li)):
    for s in range(i+1,len(li)):
        if li[i] > li[s]:
            nai += 1
    for p in range(len(li),len(li_to)):
        if li[i] > li_to[p]:
            ato += 1
point = 0
li = range(1,k)
point += nai*k+ato*sum(li)
print(point%(10*9+7))

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))
def bubble_sort(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
cnt_A = bubble_sort(A)
A_min=0
for i in range(len(A)):
  l_odd = [k for k in A if k<A[i]]
  A_min += len(l_odd)
result = int((cnt_A*K + A_min*(K-1)*K/2)%((10**9)+7))
print(result)

Submission status: Wrong Answer

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

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

mod = 1000000007

# K = 2のときの初期値が必要
B = A * 2
syokiti_A = 0
syokiti_B = 0
for i in range(N):
    for j in range(i, N):
        if A[i] > A[j]:
            syokiti_A += 1

for i in range(N*2):
    for j in range(i, N*2):
        if B[i] > B[j]:
            syokiti_B += 1

ans = int((syokiti_A + syokiti_B*K*(K-1)/2)) % mod

print(int(ans))
# NはAの項数, Kは繰り返す回数

Submission status: Wrong Answer

Solution code:
import numpy as np

MOD = 1e+9 + 7
N, K = map(int, input().split())
Alist = list(map(int, input().split()))

Alist_sorted = sorted(Alist)
tmp = 0
tmp2 = 0
for i in range(1, len(Alist)):
    if Alist_sorted[i] == Alist_sorted[i-1]:
        tmp2 += 1
    else:
        tmp2 = 0
    tmp += i - (tmp2)
ans = (tmp * ((K * (K-1) / 2) % MOD)) % MOD

Alist = Alist[::-1]
for i in range(1, len(Alist)):
    ans += ((np.sum(np.array(Alist[:i]) < Alist[i]) * K) % MOD)
    # ans = ans % MOD
# ans = ans % MOD
print(int(ans))

Submission status: Wrong Answer

Solution code:
MOD = 1000000000 + 7

N,K = map(int,input().split())
A = list(map(int,input().split()))
B = A*2
d = []

for i in range(N*2):
  num = B[i]
  target = B[i+1:]
  d.append(len([n for n in target if num > n]))
  
d_each = sum(d[:N]) - sum(d[N:])
first = sum(d[N:])
print(int( K/2*((2*first)+((K-1)*d_each)%MOD)%MOD ))

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-

import sys
import math
input = sys.stdin.readline

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

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

print(ans % 1000000007)

Submission status: Wrong Answer

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

MOD = 10 ** 9 + 7

X = 0

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

Y = 0

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

print((X * K%MOD + int((K%MOD * (K-1)%MOD)/2 * Y )) % MOD)

Submission status: Wrong Answer

Solution code:
def main():
    n, k = (int(i) for i in input().split())
    a = [int(i) for i in input().split()]
    MOD = 10**9 + 7
    ans = 0
    alpha = 0
    cur_min = a[-1]
    cur_l = [a[-1]]
    from bisect import bisect,insort
    for i in range(2,n+1):
        if a[n-i] <= cur_min:
            cur_min = a[n-i]
            cur_l.insert(0,a[n-i])
        else:
            in_idx = bisect(cur_l,a[n-i])
            cur_l.insert(in_idx,a[n-i])
            alpha += in_idx
    ans = ans + (alpha * k)%MOD
    n = len(set(a)) - 1
    ans = ans + ((k-1) * ( (n*(n+1)) // 2 )) %MOD
    ans = ans % MOD
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K   = map(int, input().split())
A=np.array(list(map(int, input().split())))
right=[]
left=[]
for i in range(N):
    right.append(np.count_nonzero(A[i:] < A[i]))
    left.append(np.count_nonzero(A[:i] < A[i]))
ans=sum(right)*int(K/2*(1+K))+sum(left)*int((K-1)/2*K)
print(ans%(10**9+7))

Submission status: Wrong Answer

Solution code:
n,K=map(int,input().split())
A=list(map(int,input().split()))
s=0
for i in range(1,n):
    k=i
    while A[k]<A[k-1]:
        A[k],A[k-1]=A[k-1],A[k]
        k-=1
        s+=1
        if k==0:
            break
j=0
l=1
S=0
while j<n-1:
    if A[j]==A[j+1]:
        l+=1
        j+=1
    else:
        S=S+l*(n-1-j)
        l=1
        j+=1
C=(s*K)%1000000007
D=int(K*(K-1)/2)
D=D%1000000007
S=S%1000000007
E=S*D%1000000007
print((C+E)%1000000007)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
def input(): return sys.stdin.readline().strip()
def gcd(x, y): return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y): return (x * y) // gcd(x, y)
MOD = 10 **9 + 7

# N = int(input())
# S = input()
N, K = map(int, input().split())
# 横
A = [int(x) for x in input().split()]
# 縦
# A = [int(input()) for _ in range(N)]
# 多次元
# L = [[int(x) for x in input().split()] for _ in range(N)]

ans = 0
tmp = 0

for i, a in enumerate(A) :
    for aa in range(i, N) :
        if a > A[aa] :
            ans += 1

for a in A :
    for aa in A :
        if a > aa :
            tmp += 1

ans = (ans * K) % MOD
ans %= MOD
ans += int(((tmp * ((K * (K - 1) % MOD) % MOD) / 2)) % MOD)
ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re, \
array, bisect, sys, random, time, copy, functools, os, queue, pdb
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, K = LI()
A = LI()

"""
2 1なら
2 1 2 1
点灯数は、左の数のほうが多いもの
2 1
2 1
2 1
の3種類
2回つなげてみたら決まる
2 1 2 1なら
K = 2で3
K=3 で 2 1 2 1 2 1で6
K=4 で2 1 2 1 2 1 2 1で10通り 4+3+2+1=
K=6なら 2 1 2 1 2 1 2 1 2 1 2 1で6+5+4+3+2+1 = 

偶奇でわける
modで割る

1 2なら
1 2 1 2で1しかない1
1 2 1 2 1 2なら3で2 + 1
1 2 1 2 1 2 1 2 なら6で3+2+1
"""
if len(set(A)) == 1:
    print(0)
    exit()

if N == 1:
    print(0)
    exit()
"""
各数字ごとに数える
"""
count_list = [[0,0] for _ in range(N)]
for i in range(N):
    a_count = 0
    for j in range(N):
        if A[i] > A[j]:
            # でかいときはメモ？
            count_list[i][0] += 1
    for j in range(0, i):
        if A[i] > A[j]:
            count_list[i][1] += 1

#  print(count_list)
ans = 0
for c in count_list:
    #  print('c', c)
    ans += ((1/2)*K*(K+1)*c[0]-K*c[1])%mod
    #  print(ans)
print(int(ans%mod))

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):
	return sum(sum(m<n for m in sequence[i+1:]) for i,n in enumerate(sequence))

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=[int(i)for i in input().split()]
b=a*2
A=sum(sum(m<n for m in a[i+1:]) for i,n in enumerate(a))
B=sum(sum(m<n for m in b[i+1:]) for i,n in enumerate(b))
c=0
d=-1
if k>2:
    for i in range(1,k):
        c+=i
        if i!=k-1:
            d+=i
print(((B-A)*c-A*d)%(10**9+7))

Submission status: Wrong Answer

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

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

print((k*(k+1)*count+k*(k-1)*countlast)/2%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:
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0

for i in range(n):
    cnt=0
    mi=0
    for j in range(n):
        if a[i]>a[j]:
            cnt=cnt+1
        if a[i]>a[j] and i>j:
            mi=mi+1
    if cnt==0:
        ans=ans+ cnt*(k-1) -mi*k
    else:
        ans=ans+ (k-1)*math.factorial(cnt) -mi*k

print(ans%((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 = round(count*K*(K-1)% (10**9+7)/2 )
ans = (a+b)% (10**9+7)
print(ans)

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(ans%R)

Submission status: Wrong Answer

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

MOD = 10 ** 9 + 7

X = 0

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

Y = 0

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

print((X * K + int((K%MOD * (K-1)%MOD)/2 * Y )) % MOD)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
#N,K = map(int,'10 998244353'.split())
Alist = list(map(int,input().split()))
#Alist = list(map(int,'10 9 8 7 5 6 3 4 2 1'.split()))
beforeTnumber = [0]*N
afterTnumber = [0]*N
beforesum = 0
aftersum = 0
mod_num = 10**9+7

for now in range(N):
    for before in range(now):
        if Alist[before] < Alist[now]:
            beforeTnumber[now] += 1
    for after in range(now,N):
        if Alist[after] < Alist[now]:
            afterTnumber[now] += 1
            
for i in range(N):
    beforesum += beforeTnumber[i]
    aftersum += afterTnumber[i]

Kaftersum = ((K/2)*(K+1))%mod_num
Kbeforesum = ((K/2)*(K-1))%mod_num

print(int((((aftersum*Kaftersum)%mod_num+(beforesum*Kbeforesum)%mod_num))%mod_num))

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:

def main2():
    len_a, kurikaesi = map(int, input().split(" "))
    A = list(map(int, input().split(" ")))

    a_nomi_tenti = 0
    iko_tonari_tenti = 0
    last = 0
    last_tonari = 0
    for index, a_base in enumerate(A):
        for ind2, more_right in enumerate(A[index+1:]):
            if a_base > more_right:
                a_nomi_tenti += 1
        for ind, a_youso in enumerate(A):
            if a_base > a_youso:
                iko_tonari_tenti += 1
    m = (kurikaesi-1)
    kosu = int((1+m) * m / 2) % (10**9+7)
    result = (a_nomi_tenti * kurikaesi) % (10**9+7) + (iko_tonari_tenti * kosu) % (10**9+7)
    print(result % (10**9+7))


main2()

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
def input(): return sys.stdin.readline().strip()
def gcd(x, y): return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y): return (x * y) // gcd(x, y)
MOD = 10 **9 + 7

# N = int(input())
# S = input()
N, K = map(int, input().split())
# 横
A = [int(x) for x in input().split()]
# 縦
# A = [int(input()) for _ in range(N)]
# 多次元
# L = [[int(x) for x in input().split()] for _ in range(N)]

ans = 0
tmp = 0

for i, a in enumerate(A) :
    for aa in range(i, N) :
        if a > A[aa] :
            ans += 1

for a in A :
    for aa in A :
        if a > aa :
            tmp += 1

ans = (ans * K) % MOD
ans %= MOD
ans += int(((tmp * ((K * (K - 1) % MOD) % MOD) / 2)))
ans %= MOD

print(ans)

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
# for p in range(k):
# 	sss += p+1
sss = k * (k+1) /2
print(round((ans * sss) % (1000000000 + 7)))

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
count = [0]*2000
A = (10**9)+7
c_in = 0
for i in range(n):
  for j, t in enumerate(a[:i]):
    c_in += int(t > a[i])
  count[a[i]-1] += 1
c_out = 0
for i in range(n):
  c_out += sum(count[:a[i]-1])
N = (k*c_in)%A + ((k*(k-1)//2)*c_out)%A
print(int(N))

Submission status: Wrong Answer

Solution code:
MOD = 1000000007
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
s1 = K**2 + K
s2 = K**2 - K

for i in range(0,N):
    fr = len(list(filter(lambda x:x > A[i], A[:i])))
    ba = len(list(filter(lambda x:x > A[i], A[i+1:])))
    ans += (0.5 * s1 * fr + (0.5 * s2 * ba)) % MOD
print(int(ans % MOD))

Submission status: Wrong Answer

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

sum = 0
sum_K = int(K * (K+1) / 2)
for i in range(N):
    before = 0
    after = 0
    Ai = A[i]
    # iより前を調べる
    for j in range(i):
        if Ai > A[j]:
            before += 1
    # iより後ろを調べる
    for j in range(i+1,N):
        if Ai > A[j]:
            after += 1
    all = before + after

    #sum += after * sum_K + before * (sum_K - K)
    sum += all * (sum_K+1) - before * K
    #print(before, after, all, sum)
    #print('{:100.3f}'.format(sum))
d = 1000000007
#print(d)
print(int(sum % d))

Submission status: Wrong Answer

Solution code:
z=list(map(int,input().split()))
a=list(map(int,input().split()))
n,b,c,d,e=z[1],0,0,0,1000000007
for i in range(z[0]):
    for j in range(z[0]-i):
        if a[i]>a[i+j]:
            b+=1
for i in range(z[0]):
    for j in range(z[0]):
        if a[i]<a[j]:
            c+=1
print((b*n+int(c*n*(n-1)/2))%e)

Submission status: Wrong Answer

Solution code:
from decimal import *
getcontext().prec = 20
n, k = map(int,input().split())
a = list(map(int,input().split()))
inner = Decimal(0)
outer = Decimal(0)
for i in range(0,n):
    for j in range(0,n):
        if a[i] > a[j]:
            outer += 1
            if i < j:
                inner += 1

print((Decimal(((inner) * (k)) + ((outer) * (Decimal(k) * (k-1)) / 2))%(1000000007)))

Submission status: Wrong Answer

Solution code:
n,k  = (int(i) for i in input().split())
a = [int(j) for j in input().split()]
b = a
#b = a * k
#print(b)
c = range(0,n)
resb = 0
ress = 0
for d in c:
 e = range(0,n)
 for f in e:
  #print(d,f)
  if b[d] > b[f]:
   #print(b[d],">",b[f])
   print(d,f)
   resb = resb + 1
  if b[d] < b[f]:
    #print(b[d],"<",b[f])
    ress = ress + 1
#print(resb)
#print(ress)
ppp = resb * k + ress * (k-1)
#print(ppp)
print(ppp % 1000000007)

Submission status: Wrong Answer

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

b = a
ans = 0

for i in range(len(b)):
  for j in range(len(b[i:])):
    if b[i] > b[j]:
      ans += 1
  

mul = (n * n-1) // 2

ans = ans * k * mul

print(ans % (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 = round(count*K*(K-1)/2 % (10**9+7))
ans = (a+b)% (10**9+7)
print(ans)

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 = numbers % (10**9 + 7) / 2
print(ans)

Submission status: Wrong Answer

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

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

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

ansA = 0
for i in range(n):#数列一つの中の転倒数を数える
	for j in range(i, n):
		if a[i] > a[j]:
			ansA += 1
ansA = ansA * k

ansB = 0
aa = list(set(a))
la = len(aa)
ansB = la * (la-1)/2
ansB = int(ansB * k * (k-1)/2)

ans = int((ansA + ansB) % (10**9+7))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)

B = 0
C = 0

for i in range(N):
    D = A[i:]
    B = (B + np.sum(D < A[i])) % (10**9 + 7)
    C = (C + np.sum(A < A[i])) % (10**9 + 7)
    
k_sum = int((K-1) * K/2) % (10**9 + 7)

E = (B * K) % (10**9 + 7)
F = (C * k_sum) % (10**9 + 7)

print(int((E+F) % (10**9 + 7)))