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:
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
    u = Counter(a)
    ul = list(u.keys())
    ul.sort(reverse = True)
    p = len(set(a))   
    ans *= k
    temp = u[ul[0]]
    for i in range(1,p):
        ans += (n-temp)*(k*(k-1)//2)
        ans %= Mod
        temp += u[ul[i]]
    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:
N,K=map(int,input().split())
A=list(map(int,input().split()))
Mod=10**9+7
ans_first=0
ans_sec=0
for i in range(len(A)-1):
  for j in range(i,len(A)):
    if A[i]>A[j]:
      ans_first+=1
for i in A:
  for j in A:
    if i > j:
      ans_sec+=1
tmp=(2*ans_first+(K-1)*ans_sec)%Mod
ans=(tmp*K)%Mod
print(ans//2)

Submission status: Wrong Answer

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

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

def factorial(n):
  x = format(n, 'b').count('1')
  return 2 ** x * (2 * n + 1)
    
a = count * factorial(K - 1) % (10 ** 9 + 7)
b = count * K % (10 ** 9 + 7)
print(a + b)

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
c=0
if len(A)>1:
  for i in range(len(A)):
    for j in range(i+1, len(A)):
      if A[i]>A[j]: c+=1
else:
  c=0
print(int(math.factorial(N)*c%(10**9+7)))

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

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

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

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

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
a0 = a[0]
an = a[n-1]
now = a0
c_self = 0
c_inter = 0
for i in range(n):
    for j in range(i,n):
        #print(i,j)
        #print("a",a[i],a[j])
        if a[i] > a[j]:
            c_self += 1
        if a[i] != a[j]:
            c_inter += 1
t =( (k-1) * k ) % (10**9 + 7)
ans = (k * c_self + t * c_inter / 2) % (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

order = 0
inlist = 0

ans = 0
for i in range(N-1):
    for j in range(N):
        if(A[i] > A[j]):
            if(i >= j):
                inlist += 1
            else:
                order += 1

    ans += ((((K * (K+1))%MOD ) // 2) * (order%MOD)) %MOD
    order = 0
    ans += ((((K * (K-1))%MOD ) // 2) * (inlist%MOD)) %MOD
    inlist = 0

print(ans % MOD)

Submission status: Wrong Answer

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


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

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


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



print(int((a1+a2)%(10**9+7)))

Submission status: Wrong Answer

Solution code:
import sys
n, k = map(int,input().split())
a = list(map(int,input().split()))
inner = int(0)
outer = int(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

b = (int(inner * int(k)) + int(outer * int(k) * int(k-1) / 2))
print(int(int(b)%1000000007))

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


cnt = 0

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

cnt = cnt % MOD

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
    cnt2 = cnt2 % MOD

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

    cnt2 = (cnt2 * tmp) % MOD

cnt = (cnt + cnt2) % MOD

print(int(cnt))

Submission status: Wrong Answer

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

sf=[0]*n
sb=[0]*n

for i in range(n):
    for j in range(n):
        if i<j:
            if a[i]>a[j]:
                sf[i]+=1
        else:
            if a[i]>a[j]:
                sb[j]+=1
ans=0
for i in range(n):
    ans+=k*sf[i]+k*(k-1)*(sf[i]+sb[i])/2

if ans>(10**9)+7:
    print(round(ans%((10**9)+7)+43))
else:
    print(ans)

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)
#print(rightlist,R)
#print(alllist,A)
K = K%mod
R = R%mod
A = A%mod
#print(K,R,A)
ans = R*K+A*K*(K-1)/2
ans1 = ans%mod
ans2=(ans+100)%mod


#print(int(ans+R))
print(int(ans1+R))
#print(int(ans2))

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) * K)%BIG_NUM) + (((((K%BIG_NUM)*((K-1)%BIG_NUM))/2)%BIG_NUM)*(cnt_bigger_elem(A)%BIG_NUM))))%BIG_NUM
#ans2 = int(((count_inversion(A) * K) + (((((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
print(ans2)## 惜しい

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
#1行で複数入力
input_list=list(map(int,input().split()))

max_value=N*K-1

#数列全体で自分より小さい数がいくつあるか
all_value = {i:0 for i in input_list}
for i in set(input_list):
    for j in input_list:
        if i> j:
            all_value[i]+=1

            
first_value = {i:0 for i in range(len(input_list))}

for i in range(len(input_list)-1):
    for j in range(i,len(input_list)):
        if input_list[i]>input_list[j]:
            first_value[i]+=1


# all_valueが公差
# valueがしょこう

import itertools 
count=0
for pos,i in enumerate(input_list):
    count += first_value[pos]*K+all_value[i]*int((K/2)*(K-1))

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

Submission status: Wrong Answer

Solution code:
import logging

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

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

def count_ponpon(sequence):
    counter = 0
    split_count = 0
    num = len(sequence)
    for i in set(sequence):
        split_count += sequence.count(i)
        counter += (num - split_count)

    return counter
        

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

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

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
Mod=10**9+7
ans_first=0
ans_sec=0
for i in range(len(A)-1):
  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
tmp=(2*ans_first+(K-1)*ans_sec)%Mod
ans=(tmp*K)%Mod
print(ans//2)

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
ans += int(k*(k-1)*ans_inc/2)%1000000007
ans = ans%1000000007
print(ans)

Submission status: Wrong Answer

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

# print(lst)
s_lst = sorted(enumerate(lst), key=lambda x: x[1])
# print(s_lst)

# print(s_lst[0][1])

# x番目にでかい数がそれ以降の部分lstにいくつあるか
def pp(x):
	p = 0
	for i in lst[s_lst[-1*x][0]:]:
		if i < s_lst[-1*x][1]:
			p += 1
	return p

# x番目にでかい数より小さいものがlstにいくつあるか
def qq(x):
	q = 0
	for j in lst:
		if j < s_lst[-1*x][1]:
			q += 1
	return q

cnt = 0
for m in range(1,n+1):
	# print(pp(m))
	# print(qq(m))
	cnt += (k*pp(m) + int(qq(m)*(k-1)*k/2))

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

Submission status: Wrong Answer

Solution code:
#B
n, k =map(int, input().split())
a=list(map(int, input().split()))
counta=0
countb=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(1, n):
    for j in range (0,i):
        if a[i]>a[j]:
            countb+=1

count=counta*(k*k+k)/2+countb*k*k/2
print(int(count%(1000000000+7)))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
rank=[]
after=[]
num1=0
num2=0
for i in range(0,N):
    num1=0
    num2=0
    for j in range(0,N):
        if(A[i]>A[j]):
            num1+=1
            if(i<j):
                num2+=1
    rank.append(num1)
    after.append(num2)
MOD=1000000007
ans=0
for i in range(0,N):
    ans+=((K*after[i])%MOD)
    ans+=((((K-1)*K/2)*rank[i])%MOD)
    ans%=MOD
if(ans<0):
    ans+=MOD
ans=int(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
"""
T=0
A=a.sorted()
for t in range(n-1):
  if A[t]==A[t+1]:
    T+=1
"""
w=len(a)
if w!=1:
  q=((w*(w-1))//2)%(10**9+7)
elif w==1:
  print(0)
  exit()

if k>=2:
  e=((k*(k-1))//2)%(10**9+7)
elif k==1:
  e=1

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:
from decimal import *
N, K = map(int, input().split())
As = list(map(int, input().split()))
MOD = 10**9 + 7


K_1 = Decimal(K)*Decimal(1+K)/Decimal(2) % Decimal(MOD)
K_2 = (K_1 - Decimal(K)) % Decimal(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 = Decimal(0)
for i in range(N):
    ans += (Decimal(res_next[i]) * K_1) % Decimal(MOD)
    ans += (Decimal(res_prev[i]) * K_2) % Decimal(MOD)
    ans %= Decimal(MOD)

print(int(ans))

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
a = list(map(int,input().split()))
inner = int(0)
outer = int(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

b = (int(inner * int(k)) + int(outer * int(k) * int(k-1) / 2))
print(int(b%int(1000000007)))

Submission status: Wrong Answer

Solution code:
import bisect
from collections import deque
import sys
MAX_INT = int(10e9)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
a = IL()

cnt = 0
for left in range(N):
  for right in range(left+1,N):
    if a[left] > a[right]:
      cnt += 1
cnt *= K

a.sort()
tmp = 0
for i in range(N-1):
  if a[i+1] > a[i]:
    tmp = i+1
  cnt += (((K-1)/2)*((2*tmp+(K-2)*tmp) %mod)) %mod

print(int(cnt) %mod)

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
    for index, a_base in enumerate(A):
        for more_right in A[index+1:]:
            if a_base > more_right:
                a_nomi_tenti += 1
        for a_youso in A:
            if a_base > a_youso:
                iko_tonari_tenti += 1

    m = (kurikaesi-1)
    kosu = int((1+m) * m / 2)
    result = (a_nomi_tenti * kurikaesi) + (iko_tonari_tenti * kosu)
    print(result % (10**9+7))


main2()

Submission status: Wrong Answer

Solution code:
import numpy as np

MOD = 1000000007
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:
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))
exit()

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(len(a)):
        l = [c(a[i],p) for p in a]
        c1.append(sum(l))
        c2.append(sum(l[i:]))
    ans = (sum(c1)%x)*kk+(sum(c2)%x)*k
    print(ans%x)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

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

mod = 10**9+7

np_a = np.array(a)

count = 0
for i in range(n):
    count += np.sum(np_a[i+1:] < a[i])
#print("count:"+str(count))

ans = 0
for rep in range(k,0,-1):
    add = (count*rep)%mod
    ans += add

print(ans)

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

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

print(int(ans))

Submission status: Wrong Answer

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

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

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



temp1=count_inversion(r)%(10**9+7)
temp2=(k*(k+1)/2)%(10**9+7)

print(int((temp1*temp2)%(10**9+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(N)

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


# 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)
b = (diff*sigma(K-1))
print ((a+b)%MOD)

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_ = int(0)
        for j in range(N):
            if A[i] > A[j]:
                count_all += 1
                if i < j:
                    count_ += 1
        count += count_all
        _count += count_
    tmp = 0
    tmp += count * (((K - 1) * K / 2) % mod) % mod
    tmp += _count * K % mod
        # import pdb; pdb.set_trace()
    print(int(tmp) % mod)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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) * K) + (((((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
print(ans2)## 惜しい

Submission status: Wrong Answer

Solution code:
INF = 1000000007

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

for i in range(len(a)):
    for j in range(len(a)):
        if i == j: continue
        #print(a[i], a[j])
        if a[i] > a[j]:
            if i < j:
                ans_i += 1
            else:
                ans_e += 1
x = ans_i * k
ans = ans_i + ans_e
p = int((k * (k-1) )/ 2)
y = int(ans * p)
print(int((x + y) % INF))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
rank=[]
after=[]
num1=0
num2=0
for i in range(0,N):
    num1=0
    num2=0
    for j in range(0,N):
        if(A[i]>A[j]):
            num1+=1
            if(i<j):
                num2+=1
    rank.append(num1)
    after.append(num2)
MOD=1000000007
ans=0
for i in range(0,N):
    ans+=((K*after[i])%MOD)
    ans+=((((K-1)*K/2)*rank[i])%MOD)
    ans%=MOD
if(ans<0):
    ans+=MOD
print(ans)

Submission status: Wrong Answer

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

cnt=0
res=0
for i in range(n):
    cnt=0
    for j in range(i+1,n):
        if a[i]>a[j]:
            cnt+=1
    res+=cnt*((k+1)*k)//2
    res%=mod

print(res)

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
for i in range(N):
    for j in range(N):
        if A[i]>A[j]:
            sougou+=1
ans=((K*junretu)%1000000007+((((sougou*K)%1000000007)*((K-1)/2))%1000000007)%1000000007)%1000000007
print(round(ans))

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()))
dabuleAlist = Alist + Alist
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]

Ksum = ((K/2)*(K+1))%mod_num

print((aftersum*(Ksum-1) + beforesum*(Ksum))%mod_num)

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(len(a)):
        l = [c(a[i],p) for p in a]
        c1.append(sum(l))
        c2.append(sum(l[i:]))
    ans = sum(c1)*kk+sum(c2)*k
    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()))

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 * (k - 1)) % big // 2) + count2 * k) % big

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

print(ans)

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)-1):
    for j in A2[i+1:]:
        if A2[i] > j:
            a[i] += 1

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split(' '))
a = 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 = (c_in*k)%A + (k*(k-1)//2)*c_out%A
print(N)

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()))
dabuleAlist = Alist + Alist
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]

Ksum = ((K/2)*(K+1))%mod_num

print((aftersum*(Ksum-1) + beforesum*(Ksum))%mod_num)

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)
    a = list(map(int,input().split()))
    c1 = []
    c2 = []
    for i in range(len(a)):
        l = [c(a[i],p) for p in a]
        c1.append(sum(l))
        c2.append(sum(l[i:]))
    ans = sum(c1)*kk+sum(c2)*k
    print(ans%x)  
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#B
n, k =map(int, input().split())
a=list(map(int, input().split()))
counta=0
countb=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(1, n):
    for j in range (0,i):
        if a[i]>a[j]:
            countb+=1

count=counta*(k*k+k)/2+countb*k*k/2
print(count%(1000000000+7))

Submission status: Wrong Answer

Solution code:
import sys
n, k = map(int,input().split())
a = list(map(int,input().split()))
inner = float(0)
outer = float(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

b = (int(inner * int(k)) + int(outer * int(k) * int(k-1) / 2))
print(int(b%1000000007))

Submission status: Wrong Answer

Solution code:
INF = 1000000007

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

for i in range(len(a)):
    for j in range(len(a)):
        if i == j: continue
        #print(a[i], a[j])
        if a[i] > a[j]:
            if i < j:
                ans_i += 1
            else:
                ans_e += 1
x = ans_i * k
ans = ans_i + ans_e
p = int((k * (k-1) )/ 2)
y = ans * p
print(int((x + y) % INF))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
once=0
for i in range(1,n):
        for y in range(1,n-i+1):
                if a[-i]-a[-i-y]<0:
                        once+=1
        #print(once)
a.sort()
more=0
for s in range(1,n):
        for t in range(1,n-s+1):
                if a[-s]-a[-s-t]>0:
                        more+=1
        #print(more)
print((once*k+more*(k-1))%(10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

c=0
for k in range(K, 0, -1):
  for i in range(N):
    for j in range(i,N):
      if l[i] > l[j]:
        c+=1
        c *= k
c = c % (10*9+7)
print(c)