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 numpy as np

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

a = np.array(a)
c = np.sort(a)[::-1]
MOD = 10 ** 9 + 7
count = 1
ans = 0
for i in a:
    b = a[count:n]
    d = len(c[c < i])
    e = len(b[b < i])
    ans += (e * k + k*(k-1)/2 * d)
    ans %= MOD
    count += 1


print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, K = rl()
MOD = 10 ** 9 + 7
A = np.array(rl())
B = np.array([])
answer = 0
for a in A:
    answer += (B > a).sum()
    B = np.append(B, a)
answer *= K
answer += (N-1) * N // 2 * (K-1) * K // 2
print(answer%MOD)
#01

Submission status: Wrong Answer

Solution code:
import numpy
n,k = map(int,input().split())
A = list(map(int,input().split()))
lis = []
count = 0
now = 0
for i in range(n):
  count = 0
  now = A[i]
  for j in range(i,n):
    if now > A[j]:
      count += 1
  lis.append(count)
print(((sum(lis)*(((k+1)*k)//2))%(10**9+7)))

Submission status: Wrong Answer

Solution code:
import numpy
n,k = map(int,input().split())
A = list(map(int,input().split()))
lis = []
count = 0
now = 0
for i in range(n):
  now = A[i]
  for j in range(i,n):
    if now > A[j]:
      count += 1
  lis.append(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
mod = 10 ** 9 + 7

cnt1 = 0
cnt2 = 0
ans = 0
for i in range(n - 1):
    cnt1 += (a[i + 1:] < a[i]).sum()
    cnt2 += (a < a[i]).sum()
cnt1 = int(cnt1) * k % mod
cnt2 = int(cnt2) * (k * (k - 1) // 2) % mod
print((cnt1 + cnt2) % mod)

Submission status: Wrong Answer

Solution code:
import numpy as np

n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
mod = 10 ** 9 + 7

cnt1 = 0
cnt2 = 0
ans = 0
for i in range(n - 1):
    cnt1 += (a[i + 1:] < a[i]).sum()
    cnt2 += (a < a[i]).sum()
cnt1 = int(cnt1)
cnt2 = int(cnt2)
print((cnt1 * k + cnt2 * (k * (k - 1) // 2)) % mod)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
ans1=0
l=0
for i in range(k):
  l+=i
for i in range(n):
  for j in a:
    if a[i]<j:
      ans+=1
for i in range(n-1):
  for j in range(i+1,n):
    if a[i]>a[j]:
      ans1+=1
print((ans1*k+(ans+ans1)*l)%(10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
MOD=10**9+7

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

B=A+A
C=[0]*N
D=[0]*N


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

for i in range(N):
    C[i]=C[i]-D[i]

c=sum(C)%MOD
d=sum(D)%MOD
K=K%MOD
t=((K*(2*d+((K-1)*c)%MOD)))%MOD//2

print(t)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
ans=0
for i in range(N):
  count=0
  for j in range(i+1,N):
    if A[i]>A[j]:
      count+=1
  ans+=count
ans*=K
ans+=((N-1)*N // 2)*(K*(K-1)//2)
print(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(N):
  count=0
  for j in range(i+1,N):
    if A[i]>A[j]:
      count+=1
  ans+=count
ans+=((N-1)*N // 2)*(K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
count=[0 for i in range(n)]
for i in range(n):
  count1=0 
  if i==n-1:
    pass
  else:
    for j in range(i+1,n):
      if l[i]>l[j]:
        count1+=1
  count[i]=count1
l1=sorted(l)
count2=[0 for i in range(n)]
for i in range(1,1+n-1):
  if l1[i]==l1[i-1]:
    count2[i]=count2[i-1]
  else:
    count2[i]=count2[i-1]+1
ans=0
for i in range(n):
  ans=ans+count2[i]*(m-1)*m//2
  ans=ans+(count[i])*m
  ans%=10**9+7
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    N, K, *a_l = map(int, open(0).read().split())
    MOD = 10**9+7
    count_a, count_b = 0, 0
    inversion = 0

    for i in range(N):
        for j in range(N):
            if a_l[i] > a_l[j]:
                if i < j:
                    count_a += 1
                count_b += 1

    inversion = count_a * K + count_b * (K * (K - 1)) // 2
    print(inversion%MOD)
    print(count_a)
    print(count_b)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

nums = []
nums_2 = []
for i in range(N):
  num = int(A[i])
  s = 0
  k = 0
  for j in range(i,N):
    if A[j] < num:
      s += 1
  nums.append(s)
  for t in range(N):
    if A[t] < num:
      k += 1
  nums_2.append(k)

result = 0
for i in range(N):
  result += ((K*(K-1))/2)*(nums_2[i]) + K*nums[i]


print(int(result%(10e+8+7)))

Submission status: Wrong Answer

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

nums = []
nums_2 = []
for i in range(N):
  num = int(A[i])
  s = 0
  k = 0
  for j in range(i,N):
    if A[j] < num:
      s += 1
  nums.append(s)
  for t in range(N):
    if A[t] < num:
      k += 1
  nums_2.append(k)

result = 0
for i in range(N):
  result += ((K*(K-1))/2)*(nums_2[i]) + K*nums[i]


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

Submission status: Wrong Answer

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

nums = []
nums_2 = []
for i in range(N):
  num = int(A[i])
  s = 0
  k = 0
  for j in range(i,N):
    if A[j] < num:
      s += 1
  nums.append(s)
  for t in range(N):
    if A[t] < num:
      k += 1
  nums_2.append(k)

result = 0
for i in range(N):
  result += ((K*(K-1))/2)*(nums_2[i]) + K*nums[i]


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

Submission status: Wrong Answer

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

nums = []
nums_2 = []
for i in range(N):
  num = int(A[i])
  s = 0
  k = 0
  for j in range(i,N):
    if A[j] < num:
      s += 1
  nums.append(s)
  for t in range(N):
    if A[t] < num:
      k += 1
  nums_2.append(k)

result = 0
for i in range(N):
  result += ((K*(K-1))/2)*(nums_2[i]) + K*nums[i]


print(int(result%(10E9+7)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

one_cnt = 0

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

two_cnt = 0
B = A*2

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

one_cnt = one_cnt % 1000000007
two_cnt = two_cnt % 1000000007
ans = one_cnt * K + two_cnt * (K-1)

print(ans%1000000007)

Submission status: Wrong Answer

Solution code:
import numpy

def merge(l, r, a):
    l1 = len(l)
    r1 = len(r)
    i,j,k=0,0,0
    while j<l1 and k<r1:
        if l[j]<=r[k]:
            a[i]=l[j]
            j+=1
        else:
            cnt[0] += l1-j
            a[i]=r[k]
            k+=1
        i+=1
    while j<l1:
        a[i]=l[j]
        j+=1
        i+=1
    return a
def merge_sort(a):
    n = len(a)
    if n==1:
        return a
    else:
        mid = n//2
        left = [0]*mid
        right = [0]*(n-mid)
        for i in range(mid):
            left[i] = a[i]
        for i in range(mid,n):
            right[i-mid]=a[i]
    merge_sort(left)
    merge_sort(right)
    merge(left,right,a)
    return a

n,k = map(int,input().split())
a = numpy.array(list(map(int,input().split())))
cnt = [0,0]
m = max(a)
for i in range(1,m+1):
    tmp=n-len(a[a!=i])-1
    cnt[1]+=(1+tmp)*tmp//2
merge_sort(a)
ans2 = (n*(n-1))//2 - cnt[0]-cnt[1]
print((cnt[0]*(1+k)*k//2+ans2*k*(k-1)//2)%(10**9+7))

Submission status: Wrong Answer

Solution code:
def merge(l, r, a):
    l1 = len(l)
    r1 = len(r)
    i,j,k=0,0,0
    while j<l1 and k<r1:
        if l[j]<=r[k]:
            a[i]=l[j]
            j+=1
        else:
            cnt[0] += l1-j
            a[i]=r[k]
            k+=1
        i+=1
    while j<l1:
        a[i]=l[j]
        j+=1
        i+=1
    return a
def merge_sort(a):
    n = len(a)
    if n==1:
        return a
    else:
        mid = n//2
        left = [0]*mid
        right = [0]*(n-mid)
        for i in range(mid):
            left[i] = a[i]
        for i in range(mid,n):
            right[i-mid]=a[i]
    merge_sort(left)
    merge_sort(right)
    merge(left,right,a)
    return a

n,k = map(int,input().split())
a = list(map(int,input().split()))
cnt = [0]
merge_sort(a)
ans1 = cnt[0]
ans3 = n-len(set(a))
ans3 = ((1+ans3)*ans3)//2
ans2 = (n*(n-1))//2 - ans1 - ans3
print((ans1*((1+k)*k)//2+ans2*(k*(k-1))//2)%(10**9+7))

Submission status: Wrong Answer

Solution code:
def merge(l, r, a):
    l1 = len(l)
    r1 = len(r)
    i,j,k=0,0,0
    while j<l1 and k<r1:
        if l[j]<=r[k]:
            a[i]=l[j]
            j+=1
        else:
            cnt[0] += l1-j
            a[i]=r[k]
            k+=1
        i+=1
    while j<l1:
        a[i]=l[j]
        j+=1
        i+=1
    return a
def merge_sort(a):
    n = len(a)
    if n==1:
        return a
    else:
        mid = n//2
        left = [0]*mid
        right = [0]*(n-mid)
        for i in range(mid):
            left[i] = a[i]
        for i in range(mid,n):
            right[i-mid]=a[i]
    merge_sort(left)
    merge_sort(right)
    merge(left,right,a)
    return a

n,k = map(int,input().split())
a = list(map(int,input().split()))
cnt = [0]
merge_sort(a)
ans3 = n-len(set(a))
ans3 = (1+ans3)*ans3//2
ans2 = n*(n-1)//2 - cnt[0]-ans3
print((cnt[0]*(1+k)*k//2+ans2*k*(k-1)//2)%(10**9+7))

Submission status: Wrong Answer

Solution code:
def merge(l, r, a):
    l1 = len(l)
    r1 = len(r)
    i,j,k=0,0,0
    while j<l1 and k<r1:
        if l[j]<r[k]:
            a[i]=l[j]
            j+=1
        elif l[j]==r[k]:
            a[i]=l[j]
            j+=1
            cnt[1] += 1
        else:
            cnt[0] += l1-j
            a[i]=r[k]
            k+=1
        i+=1
    while j<l1:
        a[i]=l[j]
        j+=1
        i+=1
    return a
def merge_sort(a):
    n = len(a)
    if n==1:
        return a
    else:
        mid = n//2
        left = [0]*mid
        right = [0]*(n-mid)
        for i in range(mid):
            left[i] = a[i]
        for i in range(mid,n):
            right[i-mid]=a[i]
    merge_sort(left)
    merge_sort(right)
    merge(left,right,a)
    return a

n,k = map(int,input().split())
a = list(map(int,input().split()))
cnt = [0,0]
merge_sort(a)
cnt[1]=(1+cnt[1])*cnt[1]//2
ans2 = n*(n-1)//2 - cnt[0]-cnt[1]
print((cnt[0]*(1+k)*k//2+ans2*k*(k-1)//2)%(10**9+7))

Submission status: Wrong Answer

Solution code:
def merge(l, r, a):
    l1 = len(l)
    r1 = len(r)
    i,j,k=0,0,0
    while j<l1 and k<r1:
        if l[j]<r[k]:
            a[i]=l[j]
            j+=1
        elif l[j]==r[k]:
            a[i]=l[j]
            j+=1
            cnt[1] += 1
        else:
            cnt[0] += l1-j
            a[i]=r[k]
            k+=1
        i+=1
    while j<l1:
        a[i]=l[j]
        j+=1
        i+=1
    return a
def merge_sort(a):
    n = len(a)
    if n==1:
        return a
    else:
        mid = n//2
        left = [0]*mid
        right = [0]*(n-mid)
        for i in range(mid):
            left[i] = a[i]
        for i in range(mid,n):
            right[i-mid]=a[i]
    merge_sort(left)
    merge_sort(right)
    merge(left,right,a)
    return a

n,k = map(int,input().split())
a = list(map(int,input().split()))
cnt = [0,0]
merge_sort(a)
ans2 = n*(n-1)//2 - cnt[0]-cnt[1]
print((cnt[0]*(1+k)*k//2+ans2*k*(k-1)//2)%(10**9+7))

Submission status: Wrong Answer

Solution code:
def merge(l, r, a):
    l1 = len(l)
    r1 = len(r)
    i,j,k=0,0,0
    while j<l1 and k<r1:
        if l[j]<r[k]:
            a[i]=l[j]
            j+=1
        elif l[j]==r[k]:
            a[i]=l[j]
            j+=1
            cnt[1] += l1-j
        else:
            cnt[0] += l1-j
            a[i]=r[k]
            k+=1
        i+=1
    while j<l1:
        a[i]=l[j]
        j+=1
        i+=1
    return a
def merge_sort(a):
    n = len(a)
    if n==1:
        return a
    else:
        mid = n//2
        left = [0]*mid
        right = [0]*(n-mid)
        for i in range(mid):
            left[i] = a[i]
        for i in range(mid,n):
            right[i-mid]=a[i]
    merge_sort(left)
    merge_sort(right)
    merge(left,right,a)
    return a

n,k = map(int,input().split())
a = list(map(int,input().split()))
cnt = [0,0]
merge_sort(a)
ans2 = n*(n-1)//2 - cnt[0]-cnt[1]
print((cnt[0]*(1+k)*k//2+ans2*k*(k-1)//2)%(10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
lists=list(map(int,input().split()))
cnt=0
for i in range(n):
    for j in range(i+1,n):
        if lists[i]>lists[j]:
            cnt+=1
cnt=(cnt*k)%(10**9+7)
import collections
dic=collections.Counter(lists)
dic=sorted(dic.items(),key=lambda x:x[0])
sums=0
uselists=[]
for i in range(len(dic)-1):
    sums+=dic[i][1]
    uselists.append(sums)
p=0
for i in range(len(dic)-1):
    p+=uselists[i]*dic[i][1]

an=(((k*(k-1)*p)//2)%(10**9+7))
print((cnt+an)%(10**9+7))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0;d=0;mod=1000000009
for i in range(n-1):
  if a[i]>a[i+1]:
    c+=1
if a[-1]<a[0]:
  d+=1
print((k*c+(d*k-1))%mod) if d==1 else print(k*c%mod)

Submission status: Wrong Answer

Solution code:
def count_inv(lst):
    ret = 0
    for i in range(len(lst)):
        for j in range(i + 1, len(lst)):
            if lst[i] > lst[j]:
                ret += 1
    return ret


def count_smaller_elements(lst):
    ret = 0
    for i in range(len(lst)):
        tmp = 0
        for j in range(len(lst)):
            if i != j and lst[i] > lst[j]:
                tmp += 1
        ret += tmp
    return ret


def main():
    N, K = map(int, input().split())
    lst_A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7

    a = count_inv(lst_A)
    print(a)
    num1 = a * K % MOD

    b = count_smaller_elements(lst_A)
    print(b)
    num2 = b * (K * (K - 1) // 2) % MOD

    ans = (num1 + num2) % 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()))
tmp = 0
tmp2 = 0
ans = 0
MOD = 10**9+7

for i in range(N-1):
  for j in range(i+1,N):
    if i == j:
      pass
    else:
      if A[i] > A[j]:
        tmp += 1
  for k in range(N):
    if A[i] > A[k]:
      tmp2 += 1  
  ans += tmp2*K*(K-1)//2+tmp*K
  ans %= MOD
  tmp = 0
  tmp2 = 0
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()]
b,m,num,mod = sorted(a),0,0,10**9+7
for i in range(1,n):
    if b[i]==b[i-1]: num+=m
    else: num,m = num+i,i
d,ans = [0]*2001,0
def add(i,x):
	while i<=n:
		d[i] += x
		i += i & -i
def get(i):
	s = 0
	while i:
		s += d[i]
		i -= i & -i
	return s
for i in range(n):
    add(a[i],1)
    ans = (ans-get(a[i])+i+1)%mod
print((ans*k+num*k*(k-1)//2)%mod)

Submission status: Wrong Answer

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

bl = 0
cl = 0
for i in range(n):
  bl += len([j for j in a_list if j > a_list[i]])
  cl += len([k for k in a_list[i:] if k < a_list[i]])
  
cnt = (((bl % 1000000007 ) * k * (k - 1) / 2) % 1000000007) + (((cl % 1000000007) * k) % 1000000007)
print(int(cnt % 1000000007))

Submission status: Wrong Answer

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

bl = 0
cl = 0
for i in range(n):
  bl += len([j for j in a_list if j > a_list[i]])
  cl += len([k for k in a_list[i:] if k < a_list[i]])
  
cnt = ((bl * k * (k - 1) / 2) % 1000000007) + ((cl * k) % 1000000007)
print(int(cnt % 1000000007))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())

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

A=A+A

count=[0]*2*N

for i in range(N):
    for j in range(i,2*N):
        if A[i]>A[j]:
            count[j]+=1
a=(sum(count[0:N]))
b=(sum(count[N:2*N]))
c=(int((a*K+b*K*(K-1)/2)))
print(c%(10**9+7))

Submission status: Wrong Answer

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

cnt=0
a=0

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

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

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

Submission status: Wrong Answer

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

cnt=0
a=0

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

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

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

Submission status: Wrong Answer

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

cnt=0
a=0

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

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

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

Submission status: Wrong Answer

Solution code:


maxs = 10 ** 9 +7
N, K = [int(x) for x in raw_input().split(' ')]
A = [int(x) for x in raw_input().split(' ')]

B = sorted(A)
res = [0] * N
ans = 0
for i in xrange(1, N):
    if B[i] > B[i-1]:
        res[i] = res[i-1] + 1
    else:
        res[i] = res[i - 1]
    
ans += (K-1) * K * sum(res) / 2
# print(res)
another = 0
for i in xrange(N):
    for j in xrange(i+1, N):
        if A[i] > A[j]:
            another += 1
ans += another * K
print(ans % maxs)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
m = 1000000000 + 7
a0 = [0] * N
a1 = [0] * N
K_sum = (1 + K-1) * (K-1) / 2
  
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            a1[i] += 1
            if i < j:
                a0[i] += 1
a0_sum = sum(a0) % m
a1_sum = sum(a1) % m
t0 = K % m
t1 = K_sum % m
ans = int(( (a0_sum * t0)%m + (a1_sum * t1) %m ) % m)
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
m = 1000000000 + 7
a0 = [0] * N
a1 = [0] * N
K_sum = (1 + K-1) * (K-1) / 2
  
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            a1[i] += 1
            if i < j:
                a0[i] += 1
t0 = (K) % m
t1 = (K_sum) % m
ans = int(((sum(a0) % m) * t0 + (sum(a1) % m)  * t1) % m)
print(ans)

Submission status: Wrong Answer

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

AA_list=A_list*2
def get_inv_num(l):
    l=list(l)
    ret=0
    for ind in range(len(l)):
        char=l[ind]
        for s_ind in range(len(l))[ind:]:
            if int(l[s_ind])<int(char):
                ret=ret+1
    return ret

def get_inv_external(l):
    import collections
    l=list(l)
    l_count=collections.Counter(l)
    ret=0
    memo={}
    for num in l:
        if str(num) in memo:
            ret=ret+memo[str(num)]
        else:
            ret_tmp=0
            for suuji in l_count:
                if int(suuji)<int(num):
                    ret_tmp=ret_tmp+l_count[suuji]
            memo[str(num)]=ret_tmp
            ret=ret+ret_tmp
    return ret
internal=get_inv_num(A_list)
external=get_inv_external(A_list)
ret=internal*K+external*(K-1)*K//2
print(ret)

Submission status: Wrong Answer

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

AA_list=A_list*2
def get_inv_num(l):
    l=list(l)
    ret=0
    for ind in range(len(l)):
        char=l[ind]
        for s_ind in range(len(l))[ind:]:
            if int(l[s_ind])<int(char):
                ret=ret+1
    return ret

def get_inv_external(l):
    import collections
    l=list(l)
    l_count=collections.Counter(l)
    ret=0
    memo={}
    for num in l:
        if str(num) in memo:
            ret=ret+memo[str(num)]
        else:
            ret_tmp=0
            for suuji in l_count:
                if int(suuji)<int(num):
                    ret_tmp=ret_tmp+l_count[suuji]
            memo[str(num)]=ret_tmp
            ret=ret+ret_tmp
    return ret
internal=get_inv_num(A_list)
external=get_inv_external(A_list)
print(internal)
print(external)
ret=internal*K+external*(K-1)*K//2
print(ret)

Submission status: Wrong Answer

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

AA_list=A_list*2
def get_inv_num(l):
    l=list(l)
    ret=0
    for ind in range(len(l)):
        char=l[ind]
        for s_ind in range(len(l))[ind:]:
            if int(l[s_ind])<int(char):
                ret=ret+1
    return ret

internal=get_inv_num(A_list)
external=get_inv_num(AA_list)-internal*2
ret=internal*K+external*(K-1)*K//2
print(ret)

Submission status: Wrong Answer

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

AA_list=A_list*2
def get_inv_num(l):
    l=list(l)
    ret=0
    for ind in range(len(l)):
        char=l[ind]
        for s_ind in range(len(l))[ind:]:
            if int(l[s_ind])<int(char):
                ret=ret+1
    return ret

internal=get_inv_num(A_list)
external=get_inv_num(AA_list)-internal
print(internal)
print(external)
ret=internal*K+external*(K-1)*K//2
print(ret)

Submission status: Wrong Answer

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

AA_list=A_list*2
def get_inv_num(l):
    l=list(l)
    ret=0
    for ind in range(len(l)):
        char=l[ind]
        for s_ind in range(len(l))[ind:]:
            if int(l[s_ind])<int(char):
                ret=ret+1
    return ret

internal=get_inv_num(A_list)
external=get_inv_num(AA_list)-2*internal
ret=internal*K+external*K*(K-1)//2
print(ret)

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-i-1):
        if(A[i] > A[i+j+1]):
            count += 1

z = 0
for k in range(K):
    z  += (k+1)

B = count * z

print(B%(10^9+7))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l=list(map(int, input().split()))
m=10**9+7
cnts1=[0]*n
cnts2=[0]*n
for i in range(n):
  for j in range(n):
    if l[i] < l[j]:
      cnts1[i]+=1
      if i > j:
        cnts2[i]+=1
res=0
for i in range(n):
  res=(res+(cnts2[i]+(k-1)%m*cnts1[i]//2)*k%m)%m
print(res)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l=list(map(int, input().split()))
m=10**9+7
cnts1=[0]*n
cnts2=[0]*n
for i in range(n):
  for j in range(n):
    if l[i] < l[j]:
      cnts1[i]+=1
      if i > j:
        cnts2[i]+=1
res=0
for i in range(n):
  res=(res+(cnts2[i]+(k-1)*cnts1[i]//2)*k)%m
print(res)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l=list(map(int, input().split()))
m=10**9+7
cnts1=[0]*n
cnts2=[0]*n
for i in range(n):
  for j in range(n):
    if l[i] < l[j]:
      cnts1[i]+=1
      if i > j:
        cnts2[i]+=1
res=0
for i in range(n):
  res=(res%m+int(cnts1[i]/2*k%m*(k-1)%m+cnts2[i]*k%m)%m)%m
print(res)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l=list(map(int, input().split()))
m=10**9+7
cnts1=[0]*n
cnts2=[0]*n
for i in range(n):
  for j in range(n):
    if l[i] < l[j]:
      cnts1[i]+=1
      if i > j:
        cnts2[i]+=1
res=0
for i in range(n):
  res+=int(cnts1[i]/2*k%m*(k-1)%m+cnts2[i]*k%m)%m
  res=res%m
print(res)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l=list(map(int, input().split()))
m=10**9+7
cnts1=[0]*n
cnts2=[0]*n
for i in range(n):
  for j in range(n):
    if l[i] < l[j]:
      cnts1[i]+=1
      if i > j:
        cnts2[i]+=1
res=0
for i in range(n):
  res+=int(cnts1[i]%m/2*k%m*(k-1)%m+cnts2[i]%m*k%m)
  res=res%m
print(res)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l=list(map(int, input().split()))
m=10**9+7
cnts1=[0]*n
cnts2=[0]*n
for i in range(n):
  for j in range(n):
    if l[i] < l[j]:
      cnts1[i]+=1
      if i > j:
        cnts2[i]+=1
res=0
for i in range(n):
  res+=int(cnts1[i]%m/2*k%m*(k-1)%m+cnts2[i]%m*k%m)%m
  res=res%m
print(res)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l=list(map(int, input().split()))
m=10**9+7
cnts1=[0]*n
cnts2=[0]*n
for i in range(n):
  for j in range(n):
    if l[i] < l[j]:
      cnts1[i]+=1
      if i > j:
        cnts2[i]+=1
res=0
for i in range(n):
  res+=int(cnts1[i]/2*k*(k-1)%m+cnts2[i]*k%m)%m
print(res)
print(cnts1)
print(cnts2)

Submission status: Wrong Answer

Solution code:
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[0 for i in range(n)]
s=[0 for i in range(n)]
ct=0
for i in range(n):
     for j in range(n):
     	if a[j]<a[i]: 
          if j>i: b[i]+=1
          s[i]+=1
sum=0
for i in range(n):
  sum+=b[i]*k
  sum%=1000000007
  sum+=s[i]*((((k-1)*k)/2)%1000000007)
  sum%=1000000007
print(int(sum%1000000007))

Submission status: Wrong Answer

Solution code:
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[0 for i in range(n)]
s=[0 for i in range(n)]
ct=0
for i in range(n):
     for j in range(n):
     	if a[j]<a[i]: 
          if j>i: b[i]+=1
          s[i]+=1
sum=0
for i in range(n):
  sum+=b[i]*k
  sum%=1000000007
  sum+=s[i]*((((k-1)*k)/2)%1000000007)
  sum%=1000000007
print(sum%1000000007)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from collections import *
import math
from bisect import *
import functools
INF = float('inf')
mod = 10**9+7

class BIT:
    def __init__(self, N):
        self.N = N
        self.bit = [0 for _ in range(N+1)]
    def add(self, x, a):
        while x <= self.N:
            self.bit[x] += a
            x += x & -x
    def sum(self, x):
        ret = 0
        while x != 0:
            ret += self.bit[x]
            x -= x & -x
        return ret

N, K = map(int, input().split())
A = [int(x) for x in input().split()]
bit = BIT(2001)
cnt = 0
for a in A:
    cnt += bit.sum(N)-bit.sum(a)
    bit.add(a, 1)
X = 0
for a in A:
    X += bit.sum(a-1)
print((cnt*K+X*(K-1)*K//2)%mod)

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 int((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:
N, K = map(int, input().split())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7

x, y = 0, 0

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

ans = x * K * (K+1) // 2 + y * (K-1) * K // 2

print(ans % mod)

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 += (query[i]*(k*(k-1)%mod))//2
    ans += (firstt[i]*(k*(k+1)%mod))//2
    ans %= mod
  print(int(ans%mod))
solve()

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 += (query[i]*(k*(k-1)%mod))
    ans += (firstt[i]*(k*(k+1)%mod))
    ans //= 2
    ans %= mod
  print(int(ans%mod))
solve()