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 math
def counter(A):
    cnt = 0
    for i,ai in enumerate(A):
        cnt += sum(a < ai for a in A[i+1:])
    return cnt

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

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

one_a = counter(A)
two_a = counter(A*2)

if len(set(A)) == 1:
    ans = 0
elif A == sorted(A,reverse=True):
    ans = one_a * sums(K)
elif A == sorted(A):
    ans = two_a * sums(K-1)
else:
    ans = ((two_a-one_a*2) * sums(K-1))  + (K*one_a)
print(int(ans)%((10**9)+7))

Submission status: Wrong Answer

Solution code:
import math
def counter(A):
    cnt = 0
    for i,ai in enumerate(A):
        cnt += sum(a < ai for a in A[i+1:])
    return cnt

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

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

one_a = counter(A)
two_a = counter(A*2)

if A == sorted(A,reverse=True):
    ans = one_a * sums(K)
elif A == sorted(A):
    ans = two_a * sums(K-1)
else:
    ans = ((two_a-one_a*2) * sums(K-1))  + (K*one_a)
print(int(ans)%((10**9)+7))

Submission status: Wrong Answer

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

countR=0
countA=0

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

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

print(int((countR * K + (countA * K * (K-1)) / 2))%(10**9+7))

Submission status: Wrong Answer

Solution code:
mod = int(1e9 + 7)

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

ans = 0
for i in range(N):
    cnt1 = len([x for x in A[i + 1:] if x < A[i]])
    mul1 = K * (K + 1) % mod // 2
    cnt2 = len([x for x in A[:i] if x < A[i]])
    mul2 = (K - 1) * K % mod // 2
    ans = (ans + cnt1 * mul1 % mod) % mod
    ans = (ans + cnt2 * mul2 % mod) % mod
print(ans)

Submission status: Wrong Answer

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

countR=0
countA=0

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

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

print(int((countR * K + countA * 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()]

countR=0
countA=0

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

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

print(int(countR * K + countA * 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)
sum = all_counter * (K-1) * K / 2 + right_counter * K
sum %= (10 ** 9 + 7)
print(int(sum))

Submission status: Wrong Answer

Solution code:
part = 0
whole = 0

mod = 1e9 + 7
ans = 0

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

for i in range(n):
    part = 0
    for j in range(i+1, n):
        if a[j] < a[i]: part += 1 
    whole = part
    for j in range(i):
        if a[j] < a[i]: whole += 1 
    ans = (ans + part * k + whole * k * (k-1) / 2) % mod

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

countFirst = 0
countSecond = 0

for i in range(len(a)):
    for j in range(len(a)):
        if a[i] > a[j] and i < j:
            countFirst = countFirst +1
            
countFirst = countFirst * k

for i in range (len(a)):
    for j in range(len(a)):
        if a[i] > a[j]:
            countSecond = countSecond + 1
            
countSecond = int(countSecond * (k-1) * k / 2)
print((countFirst + countSecond) % mod )

Submission status: Wrong Answer

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

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

#ans = ((count * K) + (count2 * K * (K-1) // 2)) % MOD
second = (count2 * (K*(K-1)/2)%MOD) % MOD

print(int((first+second)%MOD))
#print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,K = inputMap()
    A = inputList()
    
    ten = 0
    ten_zen = 0
    for i,vol in enumerate(A):
        for j,val in enumerate(A):
            if i >= j:
                if vol > val:
                    #print("{} {}".format(vol, val))
                    ten_zen += 1
                continue
            if vol > val:
                ten += 1
                ten_zen += 1
                
    ans = (K*ten) + ((K-1)*ten_zen)
    
    #print("{} {}".format(ten,ten_zen))
    print(ans%1000000007)
    
    
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,K = inputMap()
    A = inputList()
    
    ten = 0
    ten_zen = 0
    for i,vol in enumerate(A):
        for j,val in enumerate(A):
            if i >= j:
                if vol > val:
                    print("{} {}".format(vol, val))
                    ten_zen += 1
                continue
            if vol > val:
                ten += 1
                ten_zen += 1
                
    ans = (K*ten) + ((K-1)*ten_zen)
    
    #print("{} {}".format(ten,ten_zen))
    print(ans)
    
    
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = [int(x) for x in input().split()]
sortA = sorted(A)
sortUniqueA = []
for x in sortA:
    if x not in sortUniqueA:
        sortUniqueA.append(x)
order = {x:i for i,x in enumerate(sortUniqueA)}
counter = [0 for i in range(N)]
for i in range(N):
    counter[i] += order[A[i]] * K * (K-1) // 2 
    tmp = 0
    for j in range(i+1,N):
        tmp += 1 if A[j]<A[i] else 0
    counter[i] += tmp*K
print(sum(counter) % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = [int(x) for x in input().split()]
sortA = sorted(A)
order = {x:i for i,x in enumerate(sortA)}
counter = [0 for i in range(N)]
for i in range(N):
    counter[i] += order[A[i]] * K * (K-1) // 2 
    tmp = 0
    for j in range(i+1,N):
        tmp += 1 if A[j]<A[i] else 0
    counter[i] += tmp*K
print(sum(counter) % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
As = [i for i in map(int, input().split())]
MOD = 10**9 + 7

count1 = 0
count2 = 0
for i,Ai in enumerate(As):
    for j,Aj in enumerate(As):
        if Ai > Aj:
            count2 += 1
        if i >= j:
            continue
        if Ai > Aj:
            count1 += 1
        
total = count1 * K + (count2 * K*(K-1)/2) % MOD
print(int(total % (10**9+7)))

Submission status: Wrong Answer

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

count2 = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            count2 += 1
second = (count2 * (K*(K-1)/2)%MOD) % MOD

print(int((first+second)%MOD))

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
one_tento = int(one_tento)

two_tento = 0
for i in range(n):
    for j in range(n):
        if array[i] > array[j]:
            two_tento += 1
two_tento = int(two_tento)

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

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 i in range(n):
    for j in range(n):
        if array[i] > array[j]:
            two_tento += 1

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

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 i in range(n):
    for j in range(n):
        if array[i] > array[j]:
            two_tento += 1

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

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

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

whole = 0
right = 0
whole_list = []
right_list = []

for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            whole += 1
            if i < j:
                right += 1
    else:
        whole_list.append(whole)
        whole = 0
        right_list.append(right)
        right = 0

mod = 10 ** 9 + 7
ans = sum(right_list) * K % mod
ans += sum(whole_list) * (K - 1) * K // 2 % mod

print(ans)

Submission status: Wrong Answer

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

whole = 0
right = 0
whole_list = []
right_list = []

for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            whole += 1
            if i < j:
                right += 1
    else:
        whole_list.append(whole)
        whole = 0
        right_list.append(right)
        right = 0

mod = 10 ** 9 + 7
ans = sum(right_list) * K % mod
ans += sum(whole_list) * (K - 1) * K * 0.5 % mod

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a_lst = list(map(int, input().split()))
m = 10**9+7
p, q = 0, 0

for i in range(n):
    for j in range(i + 1, n):
        if a_lst[i] > a_lst[j]:
            p += 1

for i in range(n):
    for j in range(n):
        if not i == j:
            if a_lst[i] > a_lst[j]:
                q += 1

print(int((p*k + (q*k*(k-1) / 2)) % m))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import sys
import numpy as np

n, k = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=np.int32)
A = A[::-1]
mod = 10**9+7
#print(A)
ans = 0

for i,a in enumerate(A):
    if i != 0:
        tmp_A = A[:i] - a
        #print(tmp_A, len(np.where(tmp_A<0)))
        init = len(np.where(tmp_A<0)[0])
    else:
        init = 0
    tmp_A = A - a
    #print(tmp_A, len(np.where(tmp_A<0)[0]), np.where(tmp_A<0))
    #print(init*k, len(np.where(tmp_A<0)[0]), int((k-1+1)*(k-1)/2))
    ans += init*k + len(np.where(tmp_A<0)[0])*int((k-1+1)*(k-1)/2)
    #print(ans)
print(ans%mod)

Submission status: Wrong Answer

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

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

#print(cnt)
ans = 0
mod = 10**9+7
p = 0
f = -1
for i in range(N):
    d = cnt[i]
    if d == f:
        p += 1
        d_ += p 
        ans += (K*(K-1)*d_)//2
        ans %= mod
    else:
        p = 0
        d_ = 0
    f = d
    ans += (K*(K+1)*d)//2
    ans %= mod


print(ans)

Submission status: Wrong Answer

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

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

#print(cnt)
ans = 0
mod = 10**9+7
p = 0
f = -1
for i in range(N):
    d = cnt[i]
    if d == f:
        p += 1
        ans += (K*(K-1)*p)//2
        ans %= mod
    else:
        p = 0
    f = d
    ans += (K*(K+1)*d)//2
    ans %= mod


print(ans)

Submission status: Wrong Answer

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

mod = 10**9+7
ans = 0

for i in range(N):
	bs = [1 if g < A[i] else 0 for g in A]
	ans += 0.5*(sum(bs[i:]) + sum(bs[:i]))*K*(K+1) - sum(bs[:i])*K
print(int(ans)%mod)

Submission status: Wrong Answer

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

mod = 10**9+7
ans = 0

for i in range(N):
	bs = [1 if g < A[i] else 0 for g in A]
	print(bs)
	ans += 0.5*(sum(bs[i:]) + sum(bs[:i]))*K*(K+1) - sum(bs[:i])*K
print(int(ans)%mod)

Submission status: Wrong Answer

Solution code:
from math import factorial

def Combination(n):
    return int(n*(n-1)/2)

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

tentou_origin=0
tentou_two=0

for i in range(N):
    for j in range(N):
        if i!=j:
            if A[i]>A[j]:
                tentou_two+=1
                if i<j:
                    tentou_origin+=1

print((K*tentou_origin+Combination(K)*tentou_two)%1000000007)

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7

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

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

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7

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

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

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-1):
    for j in range(i, N):
        if A[i] > A[j]:
            count += 1
first = (count * K) % 1000000007

count2 = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            count2 += 1
second = (count2 * (K*(K-1)/2)) % 1000000007

print(int((first+second)%1000000007))

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7

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

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

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

p=0
p_=0
for i,j in enumerate(A):
  p+=len(list(filter(lambda x:x>j,A)))
  p_+=len(list(filter(lambda x:x<j,A[i:])))


ans=(p_*K)%mod+p*(K*(K-1)/2)%mod

print(int(ans%mod))

Submission status: Wrong Answer

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

p=0
p_=0
for i,j in enumerate(A):
  p+=len(list(filter(lambda x:x>j,A)))
  p_+=len(list(filter(lambda x:x<j,A[i:])))


ans=p_*K+p*(K*(K-1)/2)%mod

print(int(ans%mod))

Submission status: Wrong Answer

Solution code:

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

l=list(map(int,input().split()))
mod=10**9+7

ain=0
aout=0

for i in range(n):
    for j in range(n):
        if l[i]>l[j]:
            aout+=1
            if i>j:
                ain+=1
ain*=k
aout*=k*(k-1)//2
print((ain+aout)%mod)

Submission status: Wrong Answer

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

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

ain=0
aout=0

for i in range(n):
    for j in range(n):
        if l[i]>l[j]:
            aout+=1
            if i>j:
                ain+=1
ain*=k
aout*=k*(k-1)//2
print((ain+aout)%mod)

Submission status: Wrong Answer

Solution code:
mod=1e9+7
n,k=map(int,input().split())
k=k%mod
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
ans=ans%mod
a=0
for i in range(n):
    for j in range(n):
        if l[i]>l[j]:
            a+=1
a=a%mod

print(round((ans+(a*((k%mod)*(k-1)%mod))//2)%mod))

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
ans=ans%mod
a=0
for i in range(n):
    for j in range(n):
        if l[i]>l[j]:
            a+=1
a=a%mod

print(round((ans+(a*((k%mod)*(k-1)%mod))//2)%mod))

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
ans=ans%mod
a=0
for i in range(n):
    for j in range(n):
        if l[i]>l[j]:
            a+=1
a=a%mod

print(round((ans+(a*(k*(k-1)%mod))//2)%mod))

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
for i in range(n):
    for j in range(n):
        if l[i]<l[j]:
            a+=1
print(round((ans+a*k*(k-1)//2)%mod))

Submission status: Wrong Answer

Solution code:
N, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
print(sum([1 if A[i] > A[j] else 0 for i in range(N-1) for j in range(1, N)])%(10**9+7))

Submission status: Wrong Answer

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

#for i in range(1,K+1):
#    B = B + A
#print(B)
# Tentousuu
cnt = 0
for i in range(0 , N*K):
    for j in range(i, N*K):
        if (A[(i%N)] > A[(j%N)]):
            cnt = cnt + 1
#print('t=' + str(cnt))
print(cnt%(10**9+7))

Submission status: Wrong Answer

Solution code:
import sys

N, K = list(map(int, sys.stdin.readline().strip().split(" ")))
A = list(map(int, sys.stdin.readline().strip().split(" ")))

MOD = 10**9 + 7

num_self_line = [0 for _ in range(len(A))]
num_other_line = [0 for _ in range(len(A))]

for i, a in enumerate(A):
    count = 0
    count2 = 0
    for j, aj in enumerate(A):
        if (j > i) and aj > a:
            count2 += 1
        if aj > a:
            count += 1
    num_other_line[i] = count
    num_self_line[i] = count2

res = 0

for n in num_self_line:
    res = (res + n * K)%MOD

tmp = int(K*(K-1)/2) # sum to K-1
for n in num_other_line:
    res = (res + n * tmp)%MOD

print(res)

Submission status: Wrong Answer

Solution code:
import sys

N, K = list(map(int, sys.stdin.readline().strip().split(" ")))
A = list(map(int, sys.stdin.readline().strip().split(" ")))

MOD = 10**9 + 7

num_self_line = [0 for _ in range(len(A))]
num_other_line = [0 for _ in range(len(A))]

for i, a in enumerate(A):
    count = 0
    count2 = 0
    for j, aj in enumerate(A):
        """
        if (j > i) and aj < a:
            count2 += 1
        if aj < a:
            count += 1
        """
        if (j < i) and aj > a:
            count2 += 1
        if aj > a:
            count += 1
    num_other_line[i] = count
    num_self_line[i] = count2

res = 0
for n in num_self_line:
    res = (res + n * K)%MOD

tmp = int(K*(K-1)/2)

for n in num_other_line:
    res = (res + n * tmp)%MOD

print(res)

Submission status: Wrong Answer

Solution code:

N, K = map(int,input().split())
A= list((map(int, input().split())))
an = (K*(K+1))//2
a = ((K-1)*K)//2
au =0
al = 0
for i in range(N):
    for j in range(N):
        au += 1 if A[i]<A[j] and i>j else 0
        al += 1 if A[i]<A[j] and i<j else 0
    print(au,al)
print((au*an+al*a)%(10**9+7))

Submission status: Wrong Answer

Solution code:
import sys

N, K = list(map(int, sys.stdin.readline().strip().split(" ")))
A = list(map(int, sys.stdin.readline().strip().split(" ")))

MOD = 10**9 + 7

num_self_line = [0 for _ in range(len(A))]
num_other_line = [0 for _ in range(len(A))]

for i, a in enumerate(A):
    count = 0
    count2 = 0
    for j, aa in enumerate(A):
        if (j > i) and aa < a:
            count2 += 1
        if aa < a:
            count += 1
    num_other_line[i] = count
    num_self_line[i] = count2

res = 0
for n in num_self_line:
    res = (res + n * K)%MOD

tmp = int(K*(K-1)/2)

for n in num_other_line:
    res = (res + n * tmp)%MOD

print(res)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
MOD = 10**9 + 7

bl1 = A[:,None] > A[None,:]
bl2 = np.arange(N,dtype=np.int64)[:,None]
bl3 = np.arange(N,dtype=np.int64)[None,:]
mask = bl2[None] < bl3[None]
mask = bl1 & mask
ans1 = (mask*1).astype(np.int64).sum() % MOD
ans1 = ans1 * K % MOD

ans2 = (bl1 * 1).astype(np.int64).sum() % MOD
coe =int(K * (K - 1) // 2)
ans2 = ans2 * coe % MOD


print((ans1 + ans2) % MOD)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
MOD = 10**9 + 7

bl1 = A[:,None] > A[None,:]
bl2 = np.arange(N,dtype=np.int64)[:,None]
bl3 = np.arange(N,dtype=np.int64)[None,:]
mask = bl2[None] < bl3[None]
mask = bl1 & mask
ans1 = (mask*1).astype(np.int64).sum() % MOD
ans1 = ans1 * K % MOD

ans2 = (bl1 * 1).astype(np.int64).sum() % MOD
coe =int(K * (K - 1) / 2) % MOD
ans2 = ans2 * coe % MOD


print((ans1 + ans2) % MOD)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

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

    MOD = int(1e9) + 7

    count = np.zeros((N, 2001), dtype=int)

    count[0][a[0]] += 1
    for i in range(1, N):
        count[i] = count[i-1]
        count[i][a[i]] += 1
    
    for i in range(1, 2001):
        count[:, i] += count[:, i-1]
    # print(count)
    ans = 0
    for i in range(N-1):
        left = count[i][a[i]-1]
        right = count[-1][a[i]-1] - left
        if left + right == 0:
            continue
        start = (left + right) * (K - 1) + right
        end = right
        num = K
        # print(a[i], ":", left, right, start, end, num)
        ans += (num * (start + end)) // 2
        ans %= MOD
        # print((num * (start + end)) // 2)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
# import numpy as np
 
DIV_NUM = 1000000000 + 7
 
INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])
 
A = [int(x) for x in input().split()]
#AA = np.array(A , dtype='int64')

if N==1:
    print(0)
    exit()


nn=int(math.log2(2000))+1
tree = [0] * (2**nn)

def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        y = x
        z = 1
        while y > 0:
            if y % 2 == 1:
                x += z
                break
            y //= 2
            z *= 2

def BIT_sum(tree,x):
    s = 0
    while x > 0:
        s += tree[x]
        y = x
        z = 1
        while y > 0:
            if y % 2 == 1:
                x -= z
                break
            y //= 2
            z *= 2
    return s
 
answer = N*(N-1)//2
for i in A:
    answer -= BIT_sum(tree,i)
    BIT_update(tree,i)

B = sorted(A)
 
q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r
 
answer = answer * K + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np
 
DIV_NUM = 1000000000 + 7
 
INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])
 
A = [int(x) for x in input().split()]
AA = np.array(A , dtype='int64')

if N==1:
    print(0)
    exit()


nn=int(math.log2(2000))+1
tree = [0] * (2**nn)

def BIT_update(x):
    while x <= N:
        tree[x] += 1
        y = x
        z = 1
        while y > 0:
            if y % 2 == 1:
                x += z
                break
            y //= 2
            z *= 2

def BIT_sum(x):
    s = 0
    while x > 0:
        s += tree[x]
        y = x
        z = 1
        while y > 0:
            if y % 2 == 1:
                x -= z
                break
            y //= 2
            z *= 2
    return s
 
answer = N*(N-1)//2
for i in AA:
    answer -= BIT_sum(int(i))
    BIT_update(int(i))

B = sorted(A)
 
q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r
 
answer = answer * K + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np
 
DIV_NUM = 1000000000 + 7
 
INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])
 
A = [int(x) for x in input().split()]
AA = np.array(A , dtype='int64')

if N==1:
    print(0)
    exit()


nn=int(math.log2(2000))+1
tree = [0] * (2**nn)

def BIT_update(x):
    while x <= N:
        tree[x] += 1
        y = x
        z = 1
        while y > 0:
            if y % 2 == 1:
                x += z
                break
            y //= 2
            z *= 2

def BIT_sum(x):
    s = 0
    while x > 0:
        s += tree[x]
        y = x
        z = 1
        while y > 0:
            if y % 2 == 1:
                x -= z
                break
            y //= 2
            z *= 2
    return s
 
answer = N*(N-1)//2
for i in AA:
    answer -= BIT_sum(int(i))
    BIT_update(int(i))

B = sorted(A)
 
q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r
 
# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Submission status: Wrong Answer

Solution code:
import bisect
N,K = map(int,input().split())
A = list(map(int, input().split()))
B1=sorted(A)
LIM=10**9+7

Q1=0
Q2=0
for i in range(0,N):
  B2=sorted(A[i:])
  Q1 += bisect.bisect_left(B1,A[i])
  Q2 += bisect.bisect_left(B2,A[i])
  Q1 = Q1 % LIM
  Q2 = Q2 % LIM
S1=Q1
S2=Q2
ans=int(S1*K*(K-1)/2)+int(S2*(K))
print(ans % LIM)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
mod=10**9+7
import math
import bisect

nn=int(math.log2(2000))+1
BIT=[0]*(2**nn)
BIT.insert(0,0)

def bitsum(BIT,i):
  s=0
  while i>0:
    s+=BIT[i]
    i-=i&(-i)
  return s

def bitadd(BIT,i,x):
  while i<=n:
    BIT[i]+=x
    i+=i&(-i)
  return BIT

ans1=0
for i in range(n):
  ans1+=i-bitsum(BIT,A[i])
  bitadd(BIT,A[i],1)

ans2=0
A.sort()
for i in range(n-1):
  ans2+=n-bisect.bisect_right(A,A[i])

ans=(ans1*k)%mod
ans=(ans+ans2*k*(k-1)//2)%mod
print(ans)