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 bisect
mod = 10**9+7
def main():
    n,k=map(int,input().split(' '))
    a = list(map(int,input().split(' ')))
    a_fall= 0
    a_rev = sorted(a,reverse=True)
    u_cnt = 0
    for i in range(n-1):
        a_sorted = sorted(a[i+1:])
        a_fall += bisect.bisect_left(a_sorted,a[i])
        a_fall %=mod
    a_sorted = sorted(a)
    for i in a:
        u_cnt += bisect.bisect_left(a_sorted,i)
    ans = a_fall+u_cnt*(k-1)//2
    ans %= mod
    ans *= k
    ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,K =map(int,input().split())
a = list(map(int,input().split()))
# print(a*K)
count = 0
dis = 0
for i in a:
    for k in a:
        if k < i:
            count +=1
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1

    count %= (10**9+7)
K %= (10**9+7)
a = dis * K % (10**9+7)
b = round(count*K/2% (10**9+7)*(K-1)% (10**9+7))
ans = (a+b)% (10**9+7)
print(ans)

Submission status: Wrong Answer

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

num = 0
a_lst = []
for elem in input().split():
    if a_lst != [] and a_lst[-1] > int(elem):
        num += 1
    a_lst.append(int(elem))
    
b_num = num
for i in range(2, k+1):
    b_num += i * num
    if a_lst[-1] > a_lst[0]:
        b_num += (i - 1) * (num + 1)

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

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
count = 0
com = 0
for i in range(N):
	for j in range(N):
		if A[i]>A[j]:
			com +=1
	count += (K/2)*(2*com+(K-1)*com)
	com = 0
	for l in range(i):
		if A[i] > A[i-l-1]:
			com +=1
	count -= com*K
	com = 0
print(int(count%1000000007))

Submission status: Wrong Answer

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

for i in range(n):
	for j in range(n):
		if a[i] > a[j]:
			cnt2 += 1
print((int((k*(k-1)/2*cnt2)%(10**9+7))+k*cnt1)%(10**9+7))

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import collections

N, K = list(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

inner_count = count_inversion(A)

A = sorted(A)

prev = -1
duplicate = {k:1 for k,v in enumerate(A)}

A_index = 0
duplicate_index = 0
while A_index < len(A)- 1:
    if A[A_index+1] == A[A_index]:
        duplicate[A_index + 1] -= 1
        duplicate[duplicate_index] += 1
    else:
        duplicate_index = A_index
    A_index += 1
        
count = 0
for k, v in duplicate.items():
    count += (v * k * K * (K-1) )//2

count += inner_count * K

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

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
arr = arr

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

if K == 1:
  print(bubble_sort(arr) % (10**9 + 7))
else:
  arr2 = arr * 2
  cnt_1 = bubble_sort(arr)
  cnt_2 = bubble_sort(arr2)
  sabun = cnt_2 - cnt_1*2
  
  sabun_sum = int((K -1) * K * 0.5) * sabun
  
  print(int((cnt_1 * K + sabun_sum) % (10**9 + 7)))

Submission status: Wrong Answer

Solution code:
N_K = list(map(int,input().split()))

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

B = []
for i in A:
    B.append(i)
sequence=B
#print(len(tentou))
#for j in range(len(tentou)):
#    num+=tentou[j]*(10**(len(tentou)-1-j))
#print(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
count=count*N_K[1]

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

Submission status: Wrong Answer

Solution code:
import math

n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
r=2

w=len(list(set(a)))
if w!=1:
  q=((w*(w-1))//2)%(10**9+7)
elif w==1:
  print(0)
  exit()

e=((k*(k-1))//2)%(10**9+7)

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

count=0
for i in range(n):
  for j in range(n):
    if i<j:
      if a[i]>a[j]:
        count+=1
        count%(10**9+7)
k%=10**9+7
ans+=(count*k)%(10**9+7)

ans%=10**9+7

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
# スペース区切りの整数の入力
N, K = map(int, input().split())
As = list(map(int, input().split()))

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

count_base2 =0
for i in range(N):
    for j in range(N):
        if As[i] > As[j]:
            count_base2 += 1


count = count_base * K  + count_base2 * (K *(K-1)/2)

print(int(count % (pow(10, 9) + 7)))

Submission status: Wrong Answer

Solution code:

n,k=map(int,input().split())
k=k%(1000000000+7)


a=list(map(int,input().split()))
ans=0
ss=0
tt=0

for i in range(len(a)):
    p=sum([1 for j in a[i:] if a[i]>j])
    q=sum([1 for j in a if a[i]>j])
    ss+=p
    tt+=q


ss=ss%(1000000000+7)
tt=tt%(1000000000+7)
a1=ss*k%(1000000000+7)
a2=tt*(k*(k-1)/2)%(1000000000+7)



print(int((a1+a2)%(1000000000+7)))

Submission status: Wrong Answer

Solution code:
import sys
from math import factorial

MOD = 1000000007

input = sys.stdin.readline

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

a_single = 0
a_multi = 0

for i, ai in enumerate(a):
    for j in range(n):
        if ai > a[j]:
            a_single += 1
            if j > i:
                a_multi += 1

k %= MOD

fact_k = factorial(k - 1) % MOD if k > 0 else 0

a_single %= MOD
a_multi %= MOD

ans = 0
ans = (ans + (a_single * k) % MOD) % MOD
ans = (ans + (a_multi * fact_k) % MOD) % MOD

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K=(int(x) for x in input().split())
A=list(map(int,input().split()))
junretu=0
sougou=0
for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            junretu+=1
            junretu=junretu%1000000007
for i in range(N):
    for j in range(N):
        if A[i]>A[j]:
            sougou+=1
            sougou=sougou%1000000007
ans=(((K*junretu)%1000000007)+((sougou*K*(K-1)/2))%1000000007)%1000000007
print(round(ans))

Submission status: Wrong Answer

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

print(int(ans))

Submission status: Wrong Answer

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

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

d=10**9+7

c=0

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

cc=0

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

e=(K*(K-1)/2)%d

print(int(((c*K)%d+(cc*e)%d)%d))

Submission status: Wrong Answer

Solution code:

N, K = map(int, input().split())
As = list(map(int, input().split()))
MOD = 10**9 + 7


K_1 = K*(1+K) % MOD
K_1 /= 2
K_2 = (K_1 - K) % MOD

res_next = [0 for i in range(N)]
for i in range(N):
    a = As[i]
    for j in range(i+1, N):
        if a > As[j]:
            res_next[i] += 1

res_prev = [0 for i in range(N)]

for i in range(N):
    a = As[i]
    for j in range(i):
        if a > As[j]:
            res_prev[i] += 1

ans = 0
for i in range(N):
    ans += (res_next[i] * K_1) % MOD
    ans += (res_prev[i] * K_2) % MOD
    ans %= MOD

print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
a2 = a + a
def tentou (l):
    count = [0]*len(l)
    for i in range(len(l)-1):
        for j in range(i+1,len(l)):
            if l[i] > l[j]:
                count[i] += 1
    return count
v = tentou(a)
vk = [0]*len(v)
print(v)
print(vk)
for i in range(len(v)):
    vk[i] = v[i] * (k*(k+1))//2
print(vk)
S = sum(vk)
result = S % ((10**9) + 7)
print(result)

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 += np.sum(D < A[i]) % (10**9 + 7)
    C += np.sum(A < A[i]) % (10**9 + 7)
    

E = B * K % (10**9 + 7)
F = C * ((K-1) * K / 2) % (10**9 + 7)

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

Submission status: Wrong Answer

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, K = MAP()
    A = LIST()
    count = 0
    count_ = 0
    for i in range(N):
        count_all = int(0)
        count_l = int(0)
        for j in range(N):
            if A[i] > A[j]:
                count_all += 1
                if i < j:
                    count_l += 1
        count += count_all
        count_ += count_l
    if K % 2 == 0:
        tmp1 = K / 2
        tmp2 = K - 1
    else:
        tmp1 = K
        tmp2 = (K - 1)/2
        # import pdb; pdb.set_trace()
    print(int(count_ * K + (count * tmp1 % mod) * tmp2 % mod) % mod)

if __name__ == '__main__':
    main()

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 = sum(rightlist)
A  =sum(alllist)
ans = (R*K+A*K*(K-1)/2)%mod

print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
count2 = 0
count1 = 0
for num in range(N):
    A_num = A[num]
    A_tmp = np.array(A[num:N])
    count1 += np.count_nonzero(A_tmp < A_num)
    if A_num > A[0]:
        count2 += 1

count_sum = count1 * (K**2 + K)/2 % (10**9 + 7) + count2* (K**2-K)/2 % (10**9 + 7)
print(int(count_sum  ) )

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
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1

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

ans=0

k = K % 1000000007
L= (k*(k+1)//2) % 1000000007

for i in range(N):
    for j in range(N):
        if i==j:
            continue
        if A[i] > A[j]:
            if i < j:
                ans = (ans + L) % 1000000007
            else:
                ans = (ans + L-K) % 1000000007
        print(str(i)+','+str(j)+','+str(ans))

print(int(ans))

Submission status: Wrong Answer

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

big = 1000000007

dic = {}
for i in range(n) :
    if a[i] in dic :
        dic[a[i]] += 1
    else :
        dic[a[i]] = 1

dct = sorted(dic.items(), reverse=True)
count = 0
for i in range(len(dct)) :
    sum = 0
    for j in range(i+1, len(dct)) :
        sum += dct[j][1]
    count += sum

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

#print(dct)
#print(count)
#print(count2)

ans = ((count * ((k % big) * ((k - 1) % big) // 2)) % big + count2 * (k % big)) % big

#ans = ((count * ((k % big) * ((k - 1) % big) // 2) % big + count2 * (k % big)) % big

print(ans)

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:
import sys
sys.setrecursionlimit(100000000)
#input = sys.stdin.readline

def solve():
  n,k = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  mod = 10**9+7
  firstt = [0]*n
  for i in range(n-1):
    for j in range(i+1,n):
     if a[i] > a[j]:
      firstt[i] += 1
      
  secondt = [0]*n
  a2 =  a + a
  for i in range(n):
   for j in range(i+1,2*n):
    if a2[i] > a2[j]:
      secondt[i] += 1
  
  query = []
  for i in range(n):
    query.append(secondt[i]-2*firstt[i])

  ans = 0
  for i in range(n):
    
    ans += 0.5*(query[i]*(k*(k-1)%mod))
    ans += 0.5*(firstt[i]*(k*(k+1)%mod))
    ans = int(ans)
    ans %= mod
  print(ans)
solve()

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
SUM_1 = 0
for a in range(len(A)) :
    for _a in range(a+1, len(A)) :
        if A[a] > A[_a] :
            SUM_1 += 1

A2 = A+A
SUM_2 = 0
for a in range(len(A2)) :
    for _a in range(a+1, len(A2)) :
        if A2[a] > A2[_a] :
            SUM_2 += 1

S = SUM_2 - SUM_1
SUM = SUM_1
if K == 1:
    print(SUM_1 % (10**9 + 7))
else :
    for i in range(K) :
        SUM = SUM + (i*S)
    print(SUM % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A_sort=sorted(A)
Mod=10**9+7
ans_first=0
ans_sec=0
for i in range(len(A)):
  for j in range(i+1,len(A)):
    if A[i]>A[j]:
      ans_first+=1
for i in A:
  for j in A:
    if i > j:
      ans_sec+=1
K%=Mod
tmp=(2*ans_first+(K-1)*ans_sec)%Mod
ans=(tmp*K)//2%Mod
if ans < 0:
  print(0)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
input = sys.stdin.readline
 
def main():
    n,k = map(int,input().split())
    a=list(map(int,input().split()))
    cnta=0
    cntb=0
    for i in range(n-1):
        for j in range(n-1-i):
            j+=i+1
            if(a[i]>a[j]):
                cnta+=1
                cnta=int(cnta%(1000000000+7))
    for i in range(n):
        for j in range(n):
            if(a[i]>a[j] and i!=j):
                cntb+=1
                cntb=int(cntb%(1000000000+7))
    cntak=int((cnta*k)%(1000000000+7))
    x=int(((k*(k-1)/2)%(1000000000+7)))
    cntbk=int((cntb*x )%(1000000000+7))
    
    ans=int((cntak+cntbk)%(1000000000+7))
    
    print(ans)
    
main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9 + 7

def main():
    count1 = [0 for _ in range(N)]
    count2 = [0 for _ in range(N)]
    
    for i, a in enumerate(A[:-1]):
        c = 0
        for b in A[i+1:]:
            if a > b:
                c += 1
        count1[i] = c

    for i, a in enumerate(A):
        c = 0
        for b in A[:i]:
            if a > b:
                c += 1
        count2[i] = c + count1[i]

    s = (sum(count1)%MOD * K) % MOD
    s += (sum(count2)%MOD * (K-1) * K / 2) % MOD
    print(int(s%MOD))
                
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

MOD = 10**9 + 7

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

cnt = 0



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

if K >= 2:
    cnt = (cnt * K) % MOD

cnt2 = 0

if K >= 2:
    for i in range(N):
        for j in range(N):
            if A[i] < A[j]:
                cnt2 += 1

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

    cnt2 = (cnt2 * tmp) % MOD

cnt = (cnt + cnt2) % MOD

print(int(cnt))

Submission status: Wrong Answer

Solution code:

from bisect import bisect_right as br
from bisect import bisect_left as bl

def cal(num,freq):
    return (num*(1 + freq)*freq // 2)%(10**9 + 7)

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

    tento = 0
    temp = []
    length = 0
    nottento = 0
    for a in A:
        point = br(temp,a)
        if length == point:
            if length> 0:
                if temp[-1] < a:
                    nottento += length
            temp.append(a)
        else:
            tento += length - point
            leftpoint = bl(temp,a)
            nottento += leftpoint
            temp.insert(point,a)
        length += 1
    print((cal(tento,K) + cal(nottento,K-1))%(10**9 + 7))
    return
main()

Submission status: Wrong Answer

Solution code:
MOD = 1000000007
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

def sigma(k):
    #return int((1/2)*(k%MOD)*((k+1)%MOD))
    return int(((1/2)*(k)*((k+1)))%MOD)


# B = []
# for k in range(K):
#     B.extend(A)
# print (bubble_sort(B))


C = []
for k in range(2):
    C.extend(A)
cnt = bubble_sort(A)
#print (cnt)
diff = bubble_sort(C) - 2 * cnt
#print (diff)
a = (K*cnt)%MOD
b = (diff*sigma(K-1))%MOD
print ((a+b)%MOD)

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
                ans %= Mod
    p = len(set(a))   
    ans *= k
    for i in range(1,p):
        ans += (n-i)*(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:
a=input().split(" ")
N=int(a[0])
K=int(a[1])
sequence_list=input().split(" ")
sequence=[]
for i in range(0,N):
    sequence.append(int(sequence_list[i]))
count=0
for p in range(0,N):
    count1=0
    count2=0
    for q in range(0,p):
        if sequence[p]-sequence[q]>0:
            count1+=1
            print(sequence[p])
            print("a")
    if p!=N-1:
        for r in range(p,N):
            if sequence[p]-sequence[r]>0:
                count2+=1
                print(sequence[p])
                print("b")
        count+=((count1+count2)*(K-1)+count2+count2)*K/2
    else:
        count+=(count1*(K-1))*K/2
        print(sequence[p])
        print("c")
print(int(count%(10**9+7)))

Submission status: Wrong Answer

Solution code:
import math

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

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

if K != 0:
  cnt_tmp = 0
  for i in range(len(A)):
    for j in range(len(A)):
      if A[i] > A[j]:
        cnt_tmp += 1

  cnt *= K
  cnt += cnt_tmp * int((K-1)*K/2)

print(cnt % 1000000007)

Submission status: Wrong Answer

Solution code:
#B
n, k =map(int, input().split())
a=list(map(int, input().split()))
counta=0
countb=0
countasum=0
countbsum=0
count=0

for i in range(0,n-1):
    for j in range (i, n):
        if a[i]>a[j]:
            counta+=1
for i in range(0, n-1):
    for j in range (0,i):
        if a[i]>>a[j]:
            countb+=1
for i in range(0,k):
    countasum+=counta*(k-i)
for i in range(i,k):
    countbsum+=countb*(k-i)
count=countasum+countbsum
print(count%(1000000000+7))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin

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

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


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

    ans = int(( 2*ini + (K-1)*diff ) * K / 2)

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

input = lambda: stdin.readline().rstrip()
main()

Submission status: Wrong Answer

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

B=[]

counter=0
for i in range(K):
    for j in A:
        B.append(j)
for i in range(len(B)):
    for j in range(len(B)-1, i, -1):
        if B[j] < B[j-1]:
            B[j], B[j-1] = B[j-1], B[j]
            counter += 1


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

Submission status: Wrong Answer

Solution code:
P = (10**9)+7
N,K = map(int,input().split())
A = list(map(int,input().split()))
res_p = 0
res_n = 0

for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            res_p += 1
        if A[-i-1]>A[-j-1]:
            res_n += 1
res = (K * res_p)
res += (res_p + res_n) * ((K * (K-1)) / 2) 


print(int(res % P) )

Submission status: Wrong Answer

Solution code:
n, k = input().split()
N = int(n)
K = int(k)
A = [int(a) for a in input().split()]
countAList = []
countBList = []
for j in range(len(A)):
    countA = 0
    countB = 0
    for i in range(len(A)):
        if A[i] < A[j]:
            countB += 1
            if i > j:
                countA += 1
    countAList.append(countA)
    countBList.append(countB)
result = 0

for a, b in zip(countAList, countBList):
    result += K * a + int(b * K * (K - 1) / 2)
    result %= 10 ** 9 + 7
print(result % (10 ** 9 + 7))

Submission status: Wrong Answer

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

result = 0

if K == 1:
    B = A
    for i in range(N):
        for j in range(i+1, N):
            if B[i] > B[j]:
                result += 1
else:
    B = A + A
    for i in range(N):
        C = 0
        D = 0
        E = 0
        for j in range(i+1, N):
            if B[i] > B[j]:
                C += 1
        for j in range(N, N+i+1):
            if B[i] > B[j]:
                D += 1
        E = K * (K * (C + D) + C - D) / 2
        E = E % (10**9 + 7)
        result += E
        result = result % (10**9 + 7)
    result = result % (10**9 + 7)

print(int(result))

Submission status: Wrong Answer

Solution code:

N, K = map(int, input().split())
As = list(map(int, input().split()))
MOD = 10**9 + 7


K_1 = K*(1+K) % MOD
K_1 /= 2
K_2 = (K_1 - K) % MOD

res_next = [0 for i in range(N)]
for i in range(N):
    a = As[i]
    for j in range(i+1, N):
        if a > As[j]:
            res_next[i] += 1

res_prev = [0 for i in range(N)]

for i in range(N):
    a = As[i]
    for j in range(i):
        if a > As[j]:
            res_prev[i] += 1

ans = 0
for i in range(N):
    ans += (res_next[i] * K_1) % MOD
    ans += (res_prev[i] * K_2) % MOD
    ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
N,K = [int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
####まず一周の場合を求める
low=0
high=0
eq=0
for i in range(N):
  for j in range(i+1,N):
    if(ls[i]>ls[j]):
      low+=1
    elif(ls[i]<ls[j]):
      high+=1
    else:
      eq+=1
####N周の場合
ans=0
ans+=int(low*K*(K+1)/2)
ans+=int(high*K*(K-1)/2)
ans=ans%(1000000007)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
L = list(map(int, input().split()))
d = {}
Lsorted = sorted(L)
for i in range(n):
    idx = Lsorted.index(L[i])
    bigger = len([b for b in L[i:] if b<L[i]])
    d[L[i]] = [bigger,idx]
# d= num:[x,y]
# x*k + y*k*(k-1)/2を全てのkeyに対して
res = 0
for key in d:
    [x, y] = d[key]
    res += x*k + y*k*(k-1)//2
print(res % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
count = 0
com = 0
for i in range(N):
	for j in range(N):
		if A[i]>A[j]:
			com +=1
	count += (K/2)*(2*com+(K-1)*com)
	com = 0
	for l in range(i):
		if A[i] > A[i-l-1]:
			com +=1
	count -= com
	com = 0
print(int(count%1000000007))

Submission status: Wrong Answer

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

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

Q = pow(10,9) + 7

p = 0

c = 0
d = 0
for i in range(n):
    for j in range(i+1,n):
      if(a[i] > a[j]):
         c += 1
      elif(a[i] < a[j]):
         d += 1


ans = c * k % Q + c * k *(k-1)/2 % Q
ans += d*k*(k-1)/2%Q
ans = int(ans%Q)

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def mergeSortInversions(arr):
    if len(arr) == 1:
        return arr, 0
    else:
        a = arr[:len(arr)//2]
        b = arr[len(arr)//2:]
        a, ai = mergeSortInversions(a)
        b, bi = mergeSortInversions(b)
        c = []
        i = 0
        j = 0
        inversions = 0 + ai + bi
    while i < len(a) and j < len(b):
        if a[i] <= b[j]:
            c.append(a[i])
            i += 1
        else:
            c.append(b[j])
            j += 1
            inversions += (len(a)-i)
    c += a[i:]
    c += b[j:]
    return c, inversions

def mergeAndCountSplitInv(c, d):
    # c: left half, d: right half, both sorted
    nc = len(c)
    nd = len(d)
    b = [0] * (nc + nd)
    i, j = 0, 0
    splitInv = 0
    for k in range((nc + nd)):
        if i == nc: # c is used up
            b[k] = d[j]
            j += 1
            continue
        if j == nd: # d is used up
            b[k] = c[i]
            i += 1
            continue

        if c[i] <= d[j]: 
            b[k] = c[i]
            i += 1
        elif c[i] > d[j]:
            b[k] = d[j]
            splitInv += nc - i
            j += 1
    return b, splitInv

def sortCountInv(a):
    # a: list of int
    n = len(a)
    if n <= 1: # base case
        return a, 0
    c, leftInv = sortCountInv(a[ : n//2])
    d, rightInv = sortCountInv(a[n//2: ])
    b, splitInv = mergeAndCountSplitInv(c, d)
    # print(leftInv, rightInv, splitInv)
    return b, leftInv + rightInv + splitInv

def solve(N: int, K: int, A: "List[int]"):
    A_sort, inv = mergeSortInversions(A)
    t = [0] * N
    for i in range(1, N):
        if A_sort[i] > A_sort[i-1]:
            t[i] = t[i-1] + 1
        else:
            t[i] = t[i-1]
    count = inv * K + sum(t) * (K * (K-1))//2
    print(count % MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
P = (10**9)+7
N,K = map(int,input().split())
A = list(map(int,input().split()))
res_p = 0
res_n = 0

for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            res_p += 1
        if A[-i-1]>A[-j-1]:
            res_n += 1
res = (K * res_p)
res += (res_p + res_n) * ((K * (K-1)) / 2) 


print(res % P)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)
#input = sys.stdin.readline

def solve():
  n,k = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  mod = 10**9+7
  firstt = [0]*n
  for i in range(n-1):
    for j in range(i+1,n):
     if a[i] > a[j]:
      firstt[i] += 1
      
  secondt = [0]*n
  a2 =  a + a
  for i in range(n):
   for j in range(i+1,2*n):
    if a2[i] > a2[j]:
      secondt[i] += 1
  
  query = []
  for i in range(n):
    query.append(secondt[i]-2*firstt[i])

  ans = 0
  for i in range(n):
    
    ans += (0.5*(query[i]*((k*(k-1))%mod)))
    ans += (0.5*(firstt[i]*((k*(k+1))%mod)))
    ans = int(ans)%mod
  print(ans)
solve()