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())
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)




ans = counted % 1000000007
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)
MOD = 10**9 + 7

def main():
    N, K = map(int, input().split())   
    A = [int(c) for c in input().split()]
    num = 0
    for i in range(N):
        small = 0
        large = 0
        for j in range(N):
            if i == j:
                continue
            elif i < j:
                # 自分より右側に小さい
                if A[i] > A[j]:
                    small += 1
            else:
                if A[i] < A[j]:
                    large += 1
        num = small * 0.5 * (K - 1) * K + large * 0.5 * K  * (K + 1)
    num %= MOD 
    print(int(num))



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def souwa(num):
    if num % 2 == 0:
        return int((num+1) * (num/2))
    else:
        return int((num+1) * (num//2)) + ((num//2)+1)

ans = 0
for i in range(N):
    buf1 = sum(A[i] > A[j] for j in range(i+1, N))
    buf2 = sum(A[i] > a for a in A)
    ans += (buf1 * K) + (buf2 * souwa(K-1))

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

Submission status: Wrong Answer

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

def mergecount(A):
    cnt = 0
    n = len(A)
    if n>1:
        A1 = A[:n>>1]
        A2 = A[n>>1:]
        cnt += mergecount(A1)
        cnt += mergecount(A2)
        i1=0
        i2=0
        for i in range(n):
            if i2 == len(A2):
                A[i] = A1[i1]
                i1 += 1
            elif i1 == len(A1):
                A[i] = A2[i2]
                i2 += 1
            elif A1[i1] <= A2[i2]:
                A[i] = A1[i1]
                i1 += 1
            else:
                A[i] = A2[i2]
                i2 += 1
                cnt += n//2 - i1
    return cnt

print((k * (k-1) * mergecount(a) + (k-1) * (k-2) * mergecount(a[::-1])) % 1000000007)

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]*(b[1]-1)/2)
print((mozk+mo*b[1])%(1000000000+7))

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
N,K=map(int,input().split())
l=list(map(int,input().split()))

cnt=0
cntt=0
p=10**9+7
for i in range(N):
	for j in range(N):
		if l[i]>l[j] and j>i:
			cnt+=1
for k in range(N):
	for m in range(N):
		if l[k]>l[m] and k>m:
			cntt+=1
Cn=cntt*int((K-1)*K/2)+int(K*(K+1)/2)*cnt+cnt
print(Cn%p)

Submission status: Wrong Answer

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

MOD = 10**9 + 7

ansR = 0
ansL = 0

for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                ansL += 1
            if i < j:
                ansR += 1


ans = ansR*((k+1)*k/2) + ansL*((k-1)*k/2)

if ans > MOD:
    ans %= MOD
    ans += ansR

print(int(ans%MOD))

Submission status: Wrong Answer

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

AA = A + A

AA_re = list(reversed(AA))
A_re = list(reversed(A))

ans0 = 0
for i in range(N):
    a = A_re[i]
    for j in range(i + 1, N):
        b = A_re[j]
        if a < b:
            ans0 += 1


ans1 = 0
for i in range(N):
    a = AA_re[i]
    for j in range(i + 1, 2 * N):
        b = AA_re[j]
        if a < b:
            ans1 += 1


sa = ans1 - ans0
m = 10 ** 9 + 7


matu = ans0 + sa * (K - 1)
c = ans0 + matu

ans = c / 2 * K

if K == 0:
    print(int(ans0))
    exit()

ans = ans % m


print(int(ans))

Submission status: Wrong Answer

Solution code:
# スペース区切りの整数の入力
N, K = map(int, input().split())
an = list(map(int, input().split()))

# bi > bj の数
# 2 4 1  /  2 4 1  / 2 4 1
#
# 2 > 1 => 1（自身のなか）+  (N - 1) * (N - 1)
# 4 > 1 => 1（自身のなか）*  2 * (N-1) = 4
# 1 >

# N = an の長さ
# K = ブロック数

index = 0
count = 0
result_sum = 0
for a in an:
    if index == 0:
        temp = 0
        temp = len(list(filter(lambda x: a > x, sorted(an[index+1:]))))
        index += 1
        # たしこみ
        result_sum += temp * (1 + K) * K / 2
    else:
        temp = 0
        # それぞれのブロック繰り返す
        for i in range(0, K):
            #  自身のブロックの中
            for x in an[index+1:]:
                if a > x:
                    temp += 1

            # それ以降の全ブロック
            temp2 = 0
            for x in an:
                if a > x:
                    temp2 += 1
            temp += temp2 * (K - i - 1)
        result_sum += temp


print(int(result_sum) % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
N,K=(input().split())
N,K=int(N),int(K)
seq=list(input().split())
seq=[int(x) for x in seq]
print(seq)
cou=0
C=0
inc=0
for i in range(len(seq)):
    for j in range(i+1,len(seq)):
        if seq[i]>seq[j]: cou+=1
        if seq[i]<seq[j]: inc+=1
for m in range(K):
    C+=((K-m)*cou+m*inc)
print(C%(10**9+7))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))*2
count1=0
count2=0
ans=0
for i in range(2*n):
  for j in range(i+1,2*n):
    if a[i]>a[j] and j<n:
      count1+=1
      count2+=1
    elif a[i]>a[j]:
      count2+=1

if k==1:
  print(count1%(10**9+7))
else:
  ans=((count2-2*count1)*(k*(k-1)%(10**9+7)//2)+count1*k)%(10**9+7)
  print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import numpy as np

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

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

nn = []

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

    nn.append(cnt)

nn.append(0)

pp = A.argsort()[::-1]

hoge = 10**9 + 7

cnt_sum = 0
for i in range(N):
    for j in range(N):
        if A[i] == sorted(A)[-1 * (j+1)]:
            cnt = (K / 2) * (2 * nn[i] + (K-1) * ((N-1)-pp[j]))
            cnt_sum += cnt % hoge

print(int(cnt_sum % hoge))

Submission status: Wrong Answer

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

array = list(map(int, input().split()))
one_tento = 0
for i in range(n-1):
    for j in range(i+1,n):
        if array[i] > array[j]:
            one_tento += 1

two_tento = 0
for ki in range(n):
    for l in range(n):
        if array[ki] > array[l]:
            two_tento += 1

result =  (two_tento*k*(k-1))/2 + one_tento*k
print(int(result % (7 + (10 ** 9))))

Submission status: Wrong Answer

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

count = 0
for i in range(n):
    for j in range(n-i-1):
        jj = j+1+i
        if la[i] > la[jj]:
            count += 1

count2 = 0
laa = sorted(la)
for i in range(n):
    for j in range(n-i-1):
        jj = j+1+i
      
        if laa[i] < laa[jj]:
            count2 += 1
result = (count*k + (count2)*((1/2)*(k-1)*(k)))
print(int(result)%(pow(10,9)+7))

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

if ans != 0:
  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()))
B = 0
C = sorted(A)
D = 0
for j in range(N):
    for i in range(j,N):
        if A[j]>A[i]:
            B +=1
            #print(B)
B = B*K
#print(B)
if K>1:
    for k in range(N):
        #print(C.index(A[k]))
        D += int(C.index(A[k]))
        #print(D)
#print(C.index(10))
m = 0
for l in range(1,K-1):
    m+=i
#print(m)
E=D*m+B
F =7+10**9
#print(E)
print(E%F)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
A_ori = list(map(int, input().split()))
#n, k = 10, 998244353
#A_ori = [10,9,8,7,5,6,3,4,2,1]
A = sorted(A_ori, reverse=True)
f = 10 ** 9 + 7
k_res = 0
result = 0
new_A = []
index_num = []
for a in A:
    if len(new_A) == 0:
        new_A.append(a)
        index_num.append(1)
    elif new_A[-1] == a:
        index_num[-1] += 1
    else:
        new_A.append(a)
        index_num.append(1)
#print(A_ori)
#print(new_A)
#print(index_num)
index_len = len(index_num)
res = 0
for i in range(index_len):
    for j in range(index_len - 1, i, -1):
        #print(i,j)
        res += (index_num[i] * index_num[j] * ((k-1)*k/2)) % f
    #print(res)
    result += (res) % f
for i in range(n):
    for j in range(n-1, i, -1):
        if A_ori[i] > A_ori[j]:
            result+= 1
print(int(result % f))

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

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

sn = lambda : stdin.readline().rstrip()
an = lambda : map(int, stdin.readline().split())
ni = lambda : int(sn())

n, k = an()
a = list(an())

x = a[:] 
wa = []
tmp = [0] * (n+1)
for i, ai in enumerate(x):
  cnt = 0
  for j in range(i+1, n):
    if ai > x[j]:
      cnt += 1
  tcnt = 0
  for j in range(i+1):
    if ai > x[j]:
      tcnt += 1
  tmp[j] = tcnt
  wa.append(cnt)

def f(n):
  return n*(n+1)//2

mod = int(1e9)+7
ans = 0
for i, w in enumerate(wa):
  if tmp[i] != 0:
    s = w + tmp[i]
    ans += f(s * (k)) * w + w + (s + w) * (k - 1)
    ans %= mod
    continue
  ans += f(w * k) * w
  ans %= mod

print(ans)

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)%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 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
        
print(C)
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
        cnt += (K-1)*(N - 1 - rank)
    print(cnt%w)
else:
    print(0)

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)
ans =  int((K*(K-1)/2)*y) + x*K
print(int(ans%R))

Submission status: Wrong Answer

Solution code:
import numpy as np

n, k= (int(i) for i in input().split())
a = list(map(int, input().split()))

an = np.array(a)
bn = an.copy()

print(bn)

for _ in range(k-1):
  an = np.concatenate([an, bn])

ans = 0

for i in range(n * k - 1):
  #print(an[i])
  for j in range(n * k - 1):
    if(i > j):
      continue
    #print(an[i],an[j+1])
    if(an[i] > an[j+1]):
      #print("ok")
      ans += 1
ans % 1000000007
print(ans)

Submission status: Wrong Answer

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

cnt=0
C=[]
for i in range(len(A)):
    for j in range(len(A)):
        if A[i]>A[j]:
            cnt= cnt+1

print((cnt*k*(k+1)/2)%(10**9+7))

Submission status: Wrong Answer

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

right_counter = 0
all_counter = 0
threshold = 10 ** 9 + 7
threshold_right = 10 ** 9 + 7
for i in range(N):
    a_i = a_array[i]
    left_over = 0
    right_over = 0
    for j in range(i):
        if a_array[j] < a_i:
            left_over += 1
    for j in range(i+1, N):
        if a_array[j] < a_i:
            right_over += 1
    right_counter += right_over
    all_counter += (right_over + left_over)
    if right_counter >= threshold_right:
        right_counter %= threshold_right
    if all_counter >= threshold:
        all_counter %= threshold
sum = all_counter * (K-1) * K / 2 + right_counter * K
sum %= (10 ** 9 + 7)
print(int(sum))

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
mod = 10**9+7
B = A*2
c = 0
for i in range(len(B)):
  t = B[i]
  for j in range(1,len(B[i:])):
    if t > B[i+j]:
      c += 1
      #print(t,B[i+j])
#print(c)
s = sum(range(K))
print((c*s)%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 -*-
"""
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*(k-1))/2)%mod
ans += qqq*total


print(ans%mod)

Submission status: Wrong Answer

Solution code:
#B
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))


diff = []
npA = np.array(A)
lenA = len(A)
for a in A:
    temp = list(np.array([a for i in range(lenA)]) - npA)
    diff.append(temp)

D = np.array(diff)

upD = np.triu(D,k=1)

upC = np.count_nonzero(upD>0)

ans = int(K*(2*upC) - upC)
print(ans%(1000000007))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * len(A)
C = [0] * len(A)
mod = 1000000007
counter = 0
for i in range(N):
    B[i] = sum([A[i] > A[j] for j in  range(0,N)]) # Aの中でAi>Ajとなる個数
    C[i] = sum([A[i] > A[j] for j in range(i, N )]) # Aの中でAi 以降で　Ai>Ajとなる個数
    B[i] = int(B[i]) if B[i] >0 else 0

for i in range(N-1):
    c = (C[i] + (K-1)*K*B[i] / 2 )
    counter = (counter + int(c)) % mod
print(counter)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]
mod = int(10**9 + 7)
n, k = na()
a = na()


ans = 0


for i, ai in enumerate(a):
    cr = sum(x <ai for x in a[i+1:])
    cl = sum(x <ai for x in a[:i])
    ans += int(-cl +(cl+cr)*(k+1)*k/2) % mod
    ans = ans % mod
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
s_base = list(map(int,input().split()))
counter = 0
counter_base = 0
for i in range(N):
  for j in range(N - i):
    if s_base[-(i+1)] < s_base[-(i+1+j)]:
      counter_base += 1

counter_full = 0
for i in range(N):
  for j in range(N):
    if s_base[i] > s_base[j]:
      counter_full +=1
print(int((counter_base * K + K*(K-1)/2*counter_full)%(10**9+7)))

Submission status: Wrong Answer

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

count1 = 0
for i in range(N):
    for j in range(i + 1, N):
        if A[i] == minA or A[j] == minA:
            continue
        if A[i] > A[j]:
            count1 += 1

A2 = A + A[::]
# count2 = 0
# for i in range(N * 2):
#     for j in range(i + 1, N * 2):
#         if A2[i] > A2[j]:
#             count2 += 1

count2 = count1
for i in range(N):
    for j in range(i + 1, N * 2):
        # if A[i] == minA or A[j] == minA:
        #     continue
        if A2[i] > A2[j]:
            count2 += 1

A3 = A + A[::] + A[::]
# count3 = 0
# for i in range(N * 3):
#     for j in range(i + 1, N * 3):
#         if A3[i] > A3[j]:
#             count3 += 1

count3 = count2
for i in range(N):
    for j in range(i + 1, N * 3):
        if A3[i] > A3[j]:
            count3 += 1

diff1 = count2 - count1
diff2 = count3 - count2
diffx = diff2 - diff1

bn_last = diff1 + diffx * (K - 2)
bn_sum = ((diff1 + bn_last) * (K - 1)) // 2
an_sum = count1 + bn_sum

if K == 1:
    print(count1)
elif K == 2:
    print(count2)
else:
    print(an_sum % ((10 ** 9) + 7))

Submission status: Wrong Answer

Solution code:
M = 10**9+7
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))

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))

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

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

Submission status: Wrong Answer

Solution code:
# 2019/08/24
# 第一回日本最強プログラマー学生選手権-予選- - B

# Input
n, k = map(int,input().split())
a = list(map(int,input().split()))

# Calc Tentou-su Case k = 1
tento_b = 0
for i in range(n-1):
    for j in range(1, n):
        if a[i] > a[j]:
            tento_b = tento_b + 1

print(tento_b)
# Sum Tentou-su
ans = tento_b

for i in range(2, k+1):
    ans += tento_b * i

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

# Output
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    def c(x,y):
        if x > y:
            return 1
        else:
            return 0
    n,k = map(int,input().split())
    x = 1000000007
    kk = int(k*(k-1)/2)%x
    a = list(map(int,input().split()))
    c1 = []
    c2 = []
    for i in range(n):
        l = [c(a[i],p) for p in a]
        c1.append(sum(l)%x)
        c2.append(sum(l[i:])%x)
    ans = ((sum(c1)%x)*kk)%x+((sum(c2)%x)*k)%x
    print(ans%x)
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

if k == 1:
	ans = 0
	for i in range(n):
		for num in a[i+1:]:
			if a[i] > num:
				ans += 1
	print(ans)
	exit()

a = a * 2

lis = [0] * n * 2

for i in range(2*n):
	for num in a[i+1:]:
		if a[i] > num:
			lis[i] += 1

a = sum(lis[n:])
d = sum(lis[:n]) - sum(lis[n:])

ans = (2 * a + ((k-1) * d)%mod) % mod
ans = (ans * k) % mod
print((ans//2) % 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
num_down = num_up - K

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_down * count_down) % waru

print(int(result))

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 = (kkmod * y / 2) % (10 ** 9 + 7)
Kxmod = (K * x) % (10 ** 9 + 7)
ans = (Kxmod + kkmod) % (10 ** 9 + 7)
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

d0 = [0]*N
d1 = [0]*N
for i in range(N):
    d0[i] = sum(map(lambda x: x<A[i], A[i+1:N]))
    d1[i] = sum(map(lambda x: x<A[i], A))

ans = sum(d0)*(K-1)%MOD+sum(d1)*(1+K-1)*(K-1)/2%MOD
print(int(ans%MOD))

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)%1000000007+(b*t)%1000000007)%1000000007))

Submission status: Wrong Answer

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

if __name__ == '__main__':
    N,K = map(int, input().split())
    A = list(input().split())

    count = 0
    count_ = 0
    for i,a in enumerate(A):
        for target in A[i+1:]:
            if int(a) > int(target):
                count += 1

        for target in A:
            if int(a) > int(target):
                count_ += 1

    C = (count+count_*(K-(1+K)/2))%1000000007
    K = K%1000000007
    C = C*K
    C = C%1000000007
    print(C)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, K = [int(x) for x in input().strip().split()]
A = [int(x) for x in input().strip().split()]
B = A * N
T_A = 0
T_A_all = 0
for i,a in enumerate(A):
    T_A += len([1 for x in A[i+1:] if a > x])
    T_A_all += len([1 for x in A if a > x])

if T_A_all == 1:
    print(int(T_A * K + (K - 1)))
else:
    a = T_A
    z = T_A + T_A_all * (K -1)
    print(int((K/2*(a+z))%(10**9+7)))

Submission status: Wrong Answer

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

A=list(map(int,input().split()))
L=[0]*N
R=[0]*N

for i in range(N):
    for j in range(N):
        if j<i and A[j]<A[i]:
            L[i]+=1
        if j>i and A[j]<A[i]:
            R[i]+=1
ans = 0
K1=((1+K)*K/2)%(10**9+7)
K2=(K*(K-1)/2)%(10**9+7)

for i in range(N):
    ans +=(R[i]*K1+L[i]*K2)%(10**9+7)

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

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

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 + (K%MOD * (K-1)%MOD)//2 * Y ) % MOD)

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

def souwa(num):
    if num % 2 == 0:
        return int((num+1) * (num/2))
    else:
        return int((num+1) * (num//2)) + ((num//2)+1)

ans = 0
for i in range(N):
    for i in range(i+1,N):
        print("a",i)
    buf1 = sum(A[i] > A[j] for j in range(i+1, N))
    buf2 = sum(A[i] > a for a in A)
    ans += (buf1 * K) + (buf2 * souwa(K-1))

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
fflag = 0
bflag = 0

for i in range(n):
    for j in range(n):
        if i > j:
            if a[i] > a[j]:
                fflag += 1
        if i < j:
            if a[i] > a[j]:
                bflag += 1

ans = (int((fflag+bflag)*k*(k+1)/2) - fflag*k)%mod
print(ans)

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% (10**9+7))
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()))
sorted_A = sorted(A)

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

inv_sorted_A = 0
for i in range(0,N):
  for j in range(0,N):
    if i<j and sorted_A[i] < sorted_A[j]:
      inv_sorted_A += 1

count = (inv_sorted_A * (K % 1000000007) * ((K-1) % 1000000007)  + 2 * inv_A * (K % 1000000007)) % 1000000007

print(round(count/2))

Submission status: Wrong Answer

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

count = 0
for i in range(N):
    for j in range(i+1,N):
        if nums[i] > nums[j]:
            count += 1

i = K
s = count #答え
j = count*K
while i > 0:
    s += i*count
    i -= i&(-i)
print(s%(10**9+7))

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

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

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(int(K)*int(K-1)/int(2))
ans = tmp*y + x*int(K)
print(int(ans)%R)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
plus = 0
minus = 0
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i < j:
                plus += 1
            elif j < i:
                minus += 1
plus_count = plus * k
plus_count %= (10**9 +7)
tiny = plus + minus
tiny %= (10**9 +7)
num = k*(k-1)
num %= (10**9 +7)
num = int(num/2)
count = plus_count + num * tiny
print(count % (10**9 +7))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
memo = 10*100
memo = 0
for i in range(N):
  for j in range(i, N):
    if A[i] > A[j]:
      memo += 1 
memo *= K
kei = K * (K - 1) / 2
cnt = 0
for i in range(N):
  for j in range(N):
    if A[i] > A[j]:
      cnt += 1
memo = memo + cnt * int(kei)

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

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int, input().strip().split()))
count = 0
for i in range(N):
    for j in range(i,N):
        if A[i]>A[j]:
            count += 1
        else:
            count += 0
print(count*K+count)

Submission status: Wrong Answer

Solution code:
mod=1e9+7
n,k=map(int,input().split())

l=list(map(int,input().split()))
ans=0
for i in range(len(l)):
    for j in range(i):
        if l[j]>l[i]:
            ans+=1
ans*=k

l.sort()

a=0
f=0
for i in range(n-1):
    if l[i]==l[i+1]:
        a+=f
    else:
        f+=1
a+=f
print((ans+a*k*(k-1)//2)%mod)